Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F134113831
D6554.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D6554.id.diff
View Options
Index: head/bin/ed/io.c
===================================================================
--- head/bin/ed/io.c
+++ head/bin/ed/io.c
@@ -36,20 +36,24 @@
{
FILE *fp;
long size;
-
+ int cs;
fp = (*fn == '!') ? popen(fn + 1, "r") : fopen(strip_escapes(fn), "r");
if (fp == NULL) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
errmsg = "cannot open input file";
return ERR;
- } else if ((size = read_stream(fp, n)) < 0)
- return ERR;
- else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) {
+ }
+ if ((size = read_stream(fp, n)) < 0) {
+ fprintf(stderr, "%s: %s\n", fn, strerror(errno));
+ errmsg = "error reading input file";
+ }
+ if ((cs = (*fn == '!') ? pclose(fp) : fclose(fp)) < 0) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
errmsg = "cannot close input file";
- return ERR;
}
+ if (size < 0 || cs < 0)
+ return ERR;
if (!scripted)
fprintf(stdout, "%lu\n", size);
return current_addr - n;
@@ -143,19 +147,24 @@
{
FILE *fp;
long size;
+ int cs;
fp = (*fn == '!') ? popen(fn+1, "w") : fopen(strip_escapes(fn), mode);
if (fp == NULL) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
errmsg = "cannot open output file";
return ERR;
- } else if ((size = write_stream(fp, n, m)) < 0)
- return ERR;
- else if (((*fn == '!') ? pclose(fp) : fclose(fp)) < 0) {
+ }
+ if ((size = write_stream(fp, n, m)) < 0) {
+ fprintf(stderr, "%s: %s\n", fn, strerror(errno));
+ errmsg = "error writing output file";
+ }
+ if ((cs = (*fn == '!') ? pclose(fp) : fclose(fp)) < 0) {
fprintf(stderr, "%s: %s\n", fn, strerror(errno));
errmsg = "cannot close output file";
- return ERR;
}
+ if (size < 0 || cs < 0)
+ return ERR;
if (!scripted)
fprintf(stdout, "%lu\n", size);
return n ? m - n + 1 : 0;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Oct 31, 9:30 PM (4 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
24533940
Default Alt Text
D6554.id.diff (1 KB)
Attached To
Mode
D6554: Fix CID 977702 (Resource leak) in ed io.c
Attached
Detach File
Event Timeline
Log In to Comment