]> granicus.if.org Git - graphviz/commitdiff
add asserts to track down #2425
authorJohn Ellson <ellson@research.att.com>
Wed, 26 Feb 2014 15:32:09 +0000 (10:32 -0500)
committerJohn Ellson <ellson@research.att.com>
Wed, 26 Feb 2014 15:32:09 +0000 (10:32 -0500)
lib/common/htmltable.c
lib/gvc/gvloadimage.c
lib/gvc/gvrender.c
lib/gvc/gvusershape.c
plugin/pango/gvloadimage_pango.c

index 5df2a5c28a0e907f54062e37bd8f9a4f35bd17a6..86e5d356289b817faadfb481eb15ffbf1d98d26f 100644 (file)
@@ -624,6 +624,8 @@ static void emit_html_img(GVJ_t * job, htmlimg_t * cp, htmlenv_t * env)
        scale = cp->scale;
     else
        scale = env->imgscale;
+    assert(cp->src);
+    assert(cp->src[0]);
     gvrender_usershape(job, cp->src, A, 4, TRUE, scale);
 }
 
index 93706a8cffb503623ec2a4bb261f3554005c484c..718b435c21043d0a72bc69434ba4baa3813acc61 100644 (file)
@@ -51,6 +51,11 @@ void gvloadimage(GVJ_t * job, usershape_t *us, boxf b, boolean filled, const cha
     gvloadimage_engine_t *gvli;
     char type[SMALLBUF];
 
+    assert(job);
+    assert(us);
+    assert(us->name);
+    assert(us->name[0]);
+
     strcpy(type, us->stringtype);
     strcat(type, ":");
     strcat(type, target);
index 6074019293e08642369d3b4511c4700d2b7b915b..81da00074be2d9a8f398a292c6ff0fb78a09af22 100644 (file)
@@ -695,6 +695,10 @@ void gvrender_usershape(GVJ_t * job, char *name, pointf * a, int n,
     int i;
     point isz;
 
+    assert(job);
+    assert(name);
+    assert(name[0]);
+
     if (!(us = gvusershape_find(name))) {
        if (find_user_shape(name)) {
            if (gvre && gvre->library_shape)
index 880a0350af9d5cde1e60388a3a2f37a647a8cd83..d6ecc0df60aab236769d464b87effb3d02bfc9f7 100644 (file)
@@ -572,13 +572,17 @@ static Dtdisc_t ImageDictDisc = {
 
 usershape_t *gvusershape_find(char *name)
 {
-    usershape_t probe;
+    usershape_t probe, *us;
+
+    assert(name);
+    assert(name[0]);
 
     if (!ImageDict)
        return NULL;
 
     probe.name = name;
-    return (dtsearch(ImageDict, &probe));
+    us = dtsearch(ImageDict, &probe);
+    return us;
 }
 
 #define MAX_USERSHAPE_FILES_OPEN 50
@@ -589,26 +593,30 @@ boolean gvusershape_file_access(usershape_t *us)
 
     assert(us);
     assert(us->name);
+    assert(us->name[0]);
 
     if (us->f)
        fseek(us->f, 0, SEEK_SET);
     else {
-        if ((fn = safefile(us->name))) {
+        if (! (fn = safefile(us->name))) {
+           agerr(AGWARN, "Filename \"%s\" is unsafe\n", us->name);
+           return FALSE;
+       }
 #ifndef WIN32
-           us->f = fopen(fn, "r");
+       us->f = fopen(fn, "r");
 #else
-           us->f = fopen(fn, "rb");
+       us->f = fopen(fn, "rb");
 #endif
-           if (us->f == NULL) {
-               agerr(AGWARN, "%s while opening %s\n", strerror(errno), fn);
-               return FALSE;
-           }
-           if (usershape_files_open_cnt >= MAX_USERSHAPE_FILES_OPEN)
-               us->nocache = TRUE;
-           else
-               usershape_files_open_cnt++;
+       if (us->f == NULL) {
+           agerr(AGWARN, "%s while opening %s\n", strerror(errno), fn);
+           return FALSE;
        }
+       if (usershape_files_open_cnt >= MAX_USERSHAPE_FILES_OPEN)
+           us->nocache = TRUE;
+       else
+           usershape_files_open_cnt++;
     }
+    assert(us->f);
     return TRUE;
 }
 
@@ -626,6 +634,8 @@ static usershape_t *gvusershape_open (char *name)
 {
     usershape_t *us;
 
+    assert(name);
+
     if (!ImageDict)
         ImageDict = dtopen(&ImageDictDisc, Dttree);
 
@@ -637,6 +647,8 @@ static usershape_t *gvusershape_open (char *name)
        if (!gvusershape_file_access(us)) 
            return NULL;
 
+       assert(us->f);
+
         switch(imagetype(us)) {
            case FT_NULL:
                if (!(us->data = (void*)find_user_shape(us->name)))
@@ -678,11 +690,11 @@ static usershape_t *gvusershape_open (char *name)
            default:
                break;
         }
+        gvusershape_file_release(us);
         dtinsert(ImageDict, us);
+        return us;
     }
-
     gvusershape_file_release(us);
-
     return us;
 }
 
index 2d2325dfe974de846f3c512773ceea9716fdc7da..3d5b3cab4a9718a43c59378f05619113ae98549f 100644 (file)
@@ -41,8 +41,7 @@ typedef enum {
 static cairo_status_t
 reader (void *closure, unsigned char *data, unsigned int length)
 {
-    if ((FILE *)closure == NULL)
-       return CAIRO_STATUS_READ_ERROR;
+    assert(closure);
     if (length == fread(data, 1, length, (FILE *)closure)
      || feof((FILE *)closure))
         return CAIRO_STATUS_SUCCESS;
@@ -61,6 +60,7 @@ static cairo_surface_t* cairo_loadimage(GVJ_t * job, usershape_t *us)
     assert(job);
     assert(us);
     assert(us->name);
+    assert(us->name[0]);
 
     if (us->data) {
         if (us->datafree == cairo_freeimage)
@@ -74,6 +74,7 @@ static cairo_surface_t* cairo_loadimage(GVJ_t * job, usershape_t *us)
     if (!surface) { /* read file into cache */
        if (!gvusershape_file_access(us))
            return NULL;
+        assert(us->f);
         switch (us->type) {
 #ifdef CAIRO_HAS_PNG_FUNCTIONS
             case FT_PNG:
@@ -98,6 +99,11 @@ static void pango_loadimage_cairo(GVJ_t * job, usershape_t *us, boxf b, boolean
     cairo_t *cr = (cairo_t *) job->context; /* target context */
     cairo_surface_t *surface;   /* source surface */
 
+    assert(job);
+    assert(us);
+    assert(us->name);
+    assert(us->name[0]);
+
     surface = cairo_loadimage(job, us);
     if (surface) {
         cairo_save(cr);