]> git.donarmstrong.com Git - samtools.git/commitdiff
* samtools-0.1.3-13 (r260)
authorHeng Li <lh3@live.co.uk>
Tue, 5 May 2009 14:10:30 +0000 (14:10 +0000)
committerHeng Li <lh3@live.co.uk>
Tue, 5 May 2009 14:10:30 +0000 (14:10 +0000)
 * report error for file I/O error

bam_plcmd.c
bamtk.c
bgzf.c
sam.c
sam_view.c

index 23e0dd00a5eda44bbc337a17b1692adc1ecb3b8c..7bc422f508b36e13cc2a0405ac11c986357349f6 100644 (file)
@@ -304,8 +304,8 @@ int bam_pileup(int argc, char *argv[])
        {
                samfile_t *fp;
                fp = fn_list? samopen(argv[optind], "r", fn_list) : samopen(argv[optind], "rb", 0);
-               if (fp->header == 0) {
-                       fprintf(stderr, "[bam_pileup] fail to read the BAM header. Abort!\n");
+               if (fp == 0 || fp->header == 0) {
+                       fprintf(stderr, "[bam_pileup] fail to read the header: non-exisiting file or wrong format.\n");
                        return 1;
                }
                d->h = fp->header;
diff --git a/bamtk.c b/bamtk.c
index 2125ee4ea50b6c5b38cf286dad308124bbbc856f..a8972f91f2fb61d5895e935cb952f4fc1dc59329 100644 (file)
--- a/bamtk.c
+++ b/bamtk.c
@@ -3,7 +3,7 @@
 #include "bam.h"
 
 #ifndef PACKAGE_VERSION
-#define PACKAGE_VERSION "0.1.3-12 (r259)"
+#define PACKAGE_VERSION "0.1.3-13 (r260)"
 #endif
 
 int bam_taf2baf(int argc, char *argv[]);
diff --git a/bgzf.c b/bgzf.c
index 4314c70e1554efb12f8dad785eb1db894b50fde0..1b5cebe66a1cc91d3dcc6f892d37fe83bd03e11d 100644 (file)
--- a/bgzf.c
+++ b/bgzf.c
@@ -86,7 +86,9 @@ BGZF*
 open_read(int fd)
 {
     FILE* file = fdopen(fd, "r");
-    BGZF* fp = malloc(sizeof(BGZF));
+    BGZF* fp;
+       if (file == 0) return 0;
+       fp = malloc(sizeof(BGZF));
     fp->file_descriptor = fd;
     fp->open_mode = 'r';
     fp->owned_file = 0;
@@ -107,7 +109,9 @@ BGZF*
 open_write(int fd)
 {
     FILE* file = fdopen(fd, "w");
-    BGZF* fp = malloc(sizeof(BGZF));
+    BGZF* fp;
+       if (file == 0) return 0;
+       fp = malloc(sizeof(BGZF));
     fp->file_descriptor = fd;
     fp->open_mode = 'w';
     fp->owned_file = 0;
diff --git a/sam.c b/sam.c
index 85343398a8d5356a7ce1343970653adb5204a652..dd6cd3a8d8fa007bda51b897a59dd2694d25d3d7 100644 (file)
--- a/sam.c
+++ b/sam.c
@@ -79,9 +79,11 @@ samfile_t *samopen(const char *fn, const char *mode, const void *aux)
                if (mode[1] == 'b') { // binary
                        fp->type |= TYPE_BAM;
                        fp->x.bam = strcmp(fn, "-")? bam_open(fn, "r") : bam_dopen(fileno(stdin), "r");
+                       if (fp->x.bam == 0) goto open_err_ret;
                        fp->header = bam_header_read(fp->x.bam);
                } else {
                        fp->x.tamr = sam_open(fn);
+                       if (fp->x.tamr == 0) goto open_err_ret;
                        fp->header = sam_header_read2(fn_list);
                }
        } else if (mode[0] == 'w') {
@@ -89,12 +91,14 @@ samfile_t *samopen(const char *fn, const char *mode, const void *aux)
                if (mode[1] == 'b') { // binary
                        fp->type |= TYPE_BAM;
                        fp->x.bam = strcmp(fn, "-")? bam_open(fn, "w") : bam_dopen(fileno(stdout), "w");
+                       if (fp->x.bam == 0) goto open_err_ret;
                        bam_header_write(fp->x.bam, fp->header);
                } else {
                        int i;
                        bam_header_t *alt = 0;
                        alt = bam_header_parse(fp->header->text);
                        fp->x.tamw = strcmp(fn, "-")? fopen(fn, "w") : stdout;
+                       if (fp->x.tamr == 0) goto open_err_ret;
                        if (alt) {
                                if (alt->n_targets != fp->header->n_targets)
                                        fprintf(stderr, "[samopen] inconsistent number of target sequences.\n");
@@ -107,6 +111,10 @@ samfile_t *samopen(const char *fn, const char *mode, const void *aux)
                }
        }
        return fp;
+
+open_err_ret:
+       free(fp);
+       return 0;
 }
 
 void samclose(samfile_t *fp)
index 2df0530d3592893557c4cd28838452463c8dd69f..cefac2f4835e84c4d6846862b85dc59b9032badf 100644 (file)
@@ -21,7 +21,7 @@ static int usage(void);
 int main_samview(int argc, char *argv[])
 {
        int c, is_header = 0, is_header_only = 0, is_bamin = 1, ret = 0;
-       samfile_t *in, *out;
+       samfile_t *in = 0, *out = 0;
        char in_mode[4], out_mode[4], *fn_out = 0, *fn_list = 0;
 
        /* parse command-line options */
@@ -45,8 +45,14 @@ int main_samview(int argc, char *argv[])
        if (argc == optind) return usage();
 
        // open file handlers
-       in = samopen(argv[optind], in_mode, fn_list);
-       out = samopen(fn_out? fn_out : "-", out_mode, in->header);
+       if ((in = samopen(argv[optind], in_mode, fn_list)) == 0) {
+               fprintf(stderr, "[main_samview] fail to open file for reading.\n");
+               goto view_end;
+       }
+       if ((out = samopen(fn_out? fn_out : "-", out_mode, in->header)) == 0) {
+               fprintf(stderr, "[main_samview] fail to open file for writing.\n");
+               goto view_end;
+       }
        if (is_header_only) goto view_end; // no need to print alignments
 
        if (argc == optind + 1) { // convert/print the entire file