src/utils/gtfToGenePred/gtfToGenePred.c 1.7

1.7 2009/08/27 19:33:07 markd
don't dereference NULL if an annotation doesn't have an exon'
Index: src/utils/gtfToGenePred/gtfToGenePred.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/utils/gtfToGenePred/gtfToGenePred.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -b -B -U 4 -r1.6 -r1.7
--- src/utils/gtfToGenePred/gtfToGenePred.c	14 Feb 2008 00:36:46 -0000	1.6
+++ src/utils/gtfToGenePred/gtfToGenePred.c	27 Aug 2009 19:33:07 -0000	1.7
@@ -76,22 +76,36 @@
                                FILE *infoFh)
 /* convert one gtf group to a genePred */
 {
 unsigned optFields = (clGenePredExt ? genePredAllFlds : 0);
-struct genePred *gp;
 struct errCatch *errCatch = errCatchNew();
 
 if (errCatchStart(errCatch))
     {
-    gp = genePredFromGroupedGtf(gtf, group, group->name, optFields, clGxfOptions);
+    struct genePred *gp = genePredFromGroupedGtf(gtf, group, group->name, optFields, clGxfOptions);
+    if (gp == NULL)
+        {
+        if (clAllErrors)
+            fprintf(stderr,"no exons defined for %s\n", group->name);
+        else
+            errAbort("no exons defined for %s", group->name);
+        badGroupCount++;
+        }
+    else
+        {
     genePredTabOut(gp, gpFh);
     genePredFree(&gp);
     }
+    }
 errCatchEnd(errCatch);
 if (errCatch->gotError)
     {
+    // drop trailing newline in caught message
+    int l = strlen(errCatch->message->string);
+    if ((l > 0) && (errCatch->message->string[l-1] == '\n'))
+        errCatch->message->string[l-1] = '\0';
     if (clAllErrors)
-        warn("%s", errCatch->message->string);
+        fprintf(stderr, "%s\n", errCatch->message->string);
     else
         errAbort("%s", errCatch->message->string);
     badGroupCount++;
     }