summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
5d2c0d1)
check return value of malloc() in bam_cat()
wrapped fwrite() calls with error-checking
}\r
if (h) bam_header_write(fp, h);\r
\r
}\r
if (h) bam_header_write(fp, h);\r
\r
- buf = (uint8_t*) malloc(BUF_SIZE);\r
+ if ((buf = (uint8_t*) malloc(BUF_SIZE)) == NULL) {\r
+ fprintf(stderr, "[%s] failed to allocate input buffer.\n", __func__);\r
+ return -1;\r
+ }\r
for(i = 0; i < nfn; ++i){\r
BGZF *in;\r
bam_header_t *old;\r
for(i = 0; i < nfn; ++i){\r
BGZF *in;\r
bam_header_t *old;\r
fprintf(stderr, "[%s] ERROR: truncated file?: '%s'.\n", __func__, fn[i]);\r
return -1;\r
}\r
fprintf(stderr, "[%s] ERROR: truncated file?: '%s'.\n", __func__, fn[i]);\r
return -1;\r
}\r
- fwrite(ebuf, 1, len, fp_file);\r
+ if (fwrite(ebuf, 1, len, fp_file) < len) {\r
+ fprintf(stderr, "[%s] failed to write to output file.\n", __func__);\r
+ return -1;\r
+ }\r
memcpy(ebuf,ebuf+len,diff);\r
memcpy(ebuf+diff,buf,len);\r
memcpy(ebuf,ebuf+len,diff);\r
memcpy(ebuf+diff,buf,len);\r
- } else {\r
- if(j!=0) fwrite(ebuf, 1, es, fp_file);\r
+ }\r
+ else {\r
+ if(j!=0) {\r
+ if (fwrite(ebuf, 1, es, fp_file) < es) {\r
+ fprintf(stderr, "[%s] failed to write to output file.\n", __func__);\r
+ return -1;\r
+ }\r
+ }\r
len-= es;\r
memcpy(ebuf,buf+len,es);\r
len-= es;\r
memcpy(ebuf,buf+len,es);\r
- fwrite(buf, 1, len, fp_file);\r
+ if (fwrite(buf, 1, len, fp_file) < len) {\r
+ fprintf(stderr, "[%s] failed to write to output file.\n", __func__);\r
+ return -1;\r
+ }\r
if(((gzip1!=GZIPID1) || (gzip2!=GZIPID2)) || (isize!=0)) {\r
fprintf(stderr, "[%s] WARNING: Unexpected block structure in file '%s'.", __func__, fn[i]);\r
fprintf(stderr, " Possible output corruption.\n");\r
if(((gzip1!=GZIPID1) || (gzip2!=GZIPID2)) || (isize!=0)) {\r
fprintf(stderr, "[%s] WARNING: Unexpected block structure in file '%s'.", __func__, fn[i]);\r
fprintf(stderr, " Possible output corruption.\n");\r
- fwrite(ebuf, 1, es, fp_file);\r
+ if (fwrite(ebuf, 1, es, fp_file) < es) {\r
+ fprintf(stderr, " Also, failed to write final block.\n");\r
+ }\r
}\r
}\r
bam_header_destroy(old);\r
}\r
}\r
bam_header_destroy(old);\r