]> granicus.if.org Git - graphviz/commitdiff
Manually merged 1316 (scan-build fixes), 1317 (check for mmap failure in plugin code...
authorStephen C North <scnorth@gmail.com>
Tue, 13 Aug 2019 02:06:22 +0000 (22:06 -0400)
committerStephen C North <scnorth@gmail.com>
Tue, 13 Aug 2019 02:06:22 +0000 (22:06 -0400)
14 files changed:
cmd/gvmap/make_map.c
cmd/tools/graphml2gv.c
contrib/prune/generic_list.c
lib/cgraph/agerror.c
lib/gvpr/actions.c
lib/gvpr/compile.c
lib/patchwork/patchwork.c
lib/sfdpgen/sfdpinit.c
lib/sparse/DotIO.c
lib/sparse/vector.c
plugin/core/gvloadimage_core.c
plugin/core/gvrender_core_mp.c
plugin/core/gvrender_core_pic.c
plugin/lasi/gvloadimage_lasi.c

index e628d6d4e9bf6741d14c5a67e95f1aa7e5288865..f085265ae23b77e9719735c56cc0e510bd06e443 100644 (file)
@@ -891,8 +891,8 @@ void plot_dot_map(Agraph_t* gr, int n, int dim, real *x, SparseMatrix polys, Spa
   /* background color + plot label?*/
 
   if (!gr) fprintf(f, "}\n");
-  
+
+  FREE(sbuff);
 }
 
 #if 0
index b9fc9730c410c67160713d74f76e4e75bd33f486..e3ae1dbbac890aa91982dd1e32f71755af20445d 100644 (file)
@@ -773,7 +773,7 @@ int main(int argc, char **argv)
     Agraph_t *G;
     Agraph_t *prev = 0;
     FILE *inFile;
-    int rv, gcnt = 0;
+    int rv = 0, gcnt = 0;
 
 #ifdef HAVE_EXPAT
     initargs(argc, argv);
index cc856f42691fff7a3ce05eb84725ee89de147b5e..422caccbca55cf8f68584ef1cb8d2f96305af8a0 100644 (file)
@@ -34,6 +34,7 @@ generic_list_t *new_generic_list(uint64_t size)
        list->data = (gl_data *) malloc(size * sizeof(gl_data));
        if (list->data == NULL) {
            perror("[new_generic_list()] Error allocating memory:");
+           free(list);
            return NULL;
        }
     } else
index 718cefb407988d83146dea517a6f6ee7a6c1ddcb..d458f8f726855c23bf4151cfe45199113ad454d7 100644 (file)
@@ -91,8 +91,10 @@ userout (agerrlevel_t level, const char *fmt, va_list args)
        bufsz = MAX(bufsz*2,n+1);
        if ((np = (char*)realloc(buf, bufsz)) == NULL) {
            fputs("userout: could not allocate memory\n", stderr );
+           free(buf);
            return;
        }
+       buf = np;
     }
     va_end(args);
 }
index fa4aff10a5f5a5fb4e160a86a8da4dfc2b442661..2d45f9bf724b0ae08dc6dde97a89bf3d39b6346c 100644 (file)
@@ -338,7 +338,7 @@ static void cloneGraph(Agraph_t * tgt, Agraph_t * src)
                    exerror("error cloning edge (%s,%s) from graph %s",
                      agnameof(agtail(e)), agnameof(aghead(e)),
                      agnameof(src));
-               return;
+               goto done;
            }
            ep->key = e;
            ep->val = ne;
@@ -352,6 +352,7 @@ static void cloneGraph(Agraph_t * tgt, Agraph_t * src)
        }
     }
 
+done:
     dtclose (emap);
     free (data);
 }
index 2a26336ee0c3384df939626b186911638731fabf..121a0b9055e53c49bb7c8773afbe5647880330f4 100644 (file)
@@ -2473,8 +2473,10 @@ comp_prog *compileProg(parse_prog * inp, Gpr_t * state, int flags)
 
     if (flags) {
        endg_sfx = strdup (doFlags(flags, tmps));
-       if (*endg_sfx == '\0')
+       if (*endg_sfx == '\0') {
+           free(endg_sfx);
            endg_sfx = 0;
+       }
     }
 
     if (!(initDisc(state)))
index 9de4b2901324da5fbd8ce38948edf07b47e01a7f..6450906f9ef2803f06a677c60d5df83e74620c2e 100644 (file)
@@ -261,11 +261,13 @@ static void walkTree(treenode_t * tree)
 static void freeTree (treenode_t* tp)
 {
     treenode_t* cp = tp->leftchild;
+    treenode_t* rp;
     int i, nc = tp->n_children;
 
     for (i = 0; i < nc; i++) {
+       rp = cp->rightsib;
        freeTree (cp);
-       cp = cp->rightsib;
+       cp = rp;
     }
     free (tp);
 }
index 4b07a53237e3370dd4f8d83b9fbf504c092a8e0d..3e9ae243fd17ea8ca329f57771af6ba22de9f389 100644 (file)
@@ -338,6 +338,9 @@ void sfdp_layout(graph_t * g)
        graphAdjustMode(g, &am, 0);
 #endif
 
+       pad.x = PS2INCH(DFLT_MARGIN);
+       pad.y = PS2INCH(DFLT_MARGIN);
+
        if ((am.mode == AM_PRISM) && doAdjust) {
            doAdjust = 0;  /* overlap removal done in sfdp */
            ctrl->overlap = am.value;
@@ -346,9 +349,6 @@ void sfdp_layout(graph_t * g)
            if (sep.doAdd) {
                pad.x = PS2INCH(sep.x);
                pad.y = PS2INCH(sep.y);
-           } else {
-               pad.x = PS2INCH(DFLT_MARGIN);
-               pad.y = PS2INCH(DFLT_MARGIN);
            }
        }
        else {
index 6e89c5c4143ca75de723d68dd209deb287dbb9d5..a493a7858bc0fae4afba39e2d80f08f9f595d94a 100644 (file)
@@ -178,19 +178,6 @@ SparseMatrix_import_dot (Agraph_t* g, int dim, real **label_sizes, real **x, int
     val = N_NEW(nedges, real);
   }
 
-
-  if (format == FORMAT_COORD){
-    A = SparseMatrix_new(i, i, nedges, MATRIX_TYPE_REAL, format);
-    A->nz = nedges;
-    I = A->ia;
-    J = A->ja;
-    val = (real*) A->a;
-  } else {
-    I = N_NEW(nedges, int);
-    J = N_NEW(nedges, int);
-    val = N_NEW(nedges, real);
-  }
-
   sym = agattr(g, AGEDGE, "weight", NULL);
   if (D) {
     symD = agattr(g, AGEDGE, "len", NULL);
@@ -297,7 +284,10 @@ SparseMatrix_import_dot (Agraph_t* g, int dim, real **label_sizes, real **x, int
          (*x)[i*dim+3] = ww;
        } else if (dim == 1){
          nitems = sscanf(pval, "%lf", &xx);
-         if (nitems != 1) return NULL;
+         if (nitems != 1){
+           A = NULL;
+           goto done;
+          }
          (*x)[i*dim] = xx;
        } else {
          assert(0);
@@ -320,6 +310,7 @@ SparseMatrix_import_dot (Agraph_t* g, int dim, real **label_sizes, real **x, int
 
   if (D) *D = SparseMatrix_from_coordinate_arrays(nedges, nnodes, nnodes, I, J, valD, type, sz);
 
+done:
   if (format != FORMAT_COORD){
     FREE(I);
     FREE(J);
index a8b401b802733cd589d2cde02abffaecd6447a19..798d690ab2314f2e949330afc302f3188bad6d7e 100644 (file)
@@ -24,7 +24,10 @@ Vector Vector_new(int maxlen, size_t size_of_elem, void (*deallocator)(void *v))
   v->size_of_elem = size_of_elem;
   v->deallocator = deallocator;
   v->v = malloc(size_of_elem*maxlen);
-  if (!v->v) return NULL;
+  if (!v->v){
+    free(v);
+    return NULL;
+  }
   return v;
 }
 
index d9bbc0b108ea96677cbc41510d7af1c7481f1ba0..21e1e1490f5f51651d578b8d4e4e927267ebcc48 100644 (file)
@@ -177,6 +177,8 @@ static void core_loadimage_ps(GVJ_t * job, usershape_t *us, boxf b, boolean fill
                us->datasize = statbuf.st_size;
 #ifdef HAVE_SYS_MMAN_H
                us->data = mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
+               if (us->data == MAP_FAILED)
+                       us->data = NULL;
 #else
                us->data = malloc(statbuf.st_size);
                read(fd, us->data, statbuf.st_size);
index d027d998012e831afc48d29ccc961efff5138553..a751a8080ab5900b7ff4512ef2e828e2b70dc99d 100644 (file)
@@ -404,7 +404,7 @@ static void mp_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start,
     gvprintf(job, " %s\n", buffer);      /* print points */
     free(buffer);
     for (i = 0; i < count; i++) {
-        gvprintf(job, " %d", i % (count - 1) ? 1 : 0);   /* -1 on all */
+        gvprintf(job, " %d", i % (count + 1) ? 1 : 0);   /* -1 on all */
     }
     gvputs(job, "\n");
 }
index ec4ead3f43e98ea5d615f5d2300ee15decf49528..a2f790e07a309d5795f9346256d4f79030c8a691 100644 (file)
@@ -475,7 +475,7 @@ static void pic_bezier(GVJ_t * job, pointf * A, int n, int arrow_at_start,
     gvprintf(job, " %s\n", buffer);      /* print points */
     free(buffer);
     for (i = 0; i < count; i++) {
-        gvprintf(job, " %d", i % (count - 1) ? 1 : 0);   /* -1 on all */
+        gvprintf(job, " %d", i % (count + 1) ? 1 : 0);   /* -1 on all */
     }
     gvputs(job, "\n");
 }
index fd65e453a31bbc9b55fe41ed982ff96d987315be..d2a4b174618db732f1374af122dfcbbbba66233d 100644 (file)
@@ -73,6 +73,8 @@ static void lasi_loadimage_ps(GVJ_t * job, usershape_t *us, boxf b, boolean fill
                us->datasize = statbuf.st_size;
 #if HAVE_SYS_MMAN_H
                us->data = mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
+               if (us->data == MAP_FAILED)
+                       us->data = NULL;
 #else
                us->data = malloc(statbuf.st_size);
                read(fd, us->data, statbuf.st_size);