]> granicus.if.org Git - graphviz/commitdiff
tools: initialize a variable
authorCosta Shulyupin <constantine.shulyupin@gmail.com>
Sun, 27 Mar 2022 04:07:38 +0000 (07:07 +0300)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 2 Apr 2022 18:59:53 +0000 (11:59 -0700)
Squashing
warning: ‘sym’ may be used uninitialized in this function

Here was no real usage of uninitialized variable, but
compiler still complains.

Pointer sym is allocated when flag with_val is set:

    if (with_val) {
        sym = agattr(g, AGEDGE, "len", "1");
    }

So just squash the warning by setting the
pointer to NULL and test it in guard condition
instead of testing the flag:

            if (sym && val) {
                sprintf(buf, "%f", val[j]);
                agxset(e, sym, buf);
            }

cmd/tools/mm2gv.c

index 56c76f1bf547156b87107a241d4389a0ce1c9e4b..956e7569e898609f81a5994d875254739d983f2e 100644 (file)
@@ -82,7 +82,7 @@ static Agraph_t *makeDotGraph(SparseMatrix A, char *name, int dim,
     agxbuf xb;
     char buf[BUFS];
     unsigned char string[BUFS];
-    Agsym_t *sym, *sym2 = NULL, *sym3 = NULL;
+    Agsym_t *sym = NULL, *sym2 = NULL, *sym3 = NULL;
     int *ia = A->ia;
     int *ja = A->ja;
     double *val = (double *) (A->a);
@@ -181,7 +181,7 @@ static Agraph_t *makeDotGraph(SparseMatrix A, char *name, int dim,
        for (j = ia[i]; j < ia[i + 1]; j++) {
            h = arr[ja[j]];
            e = agedge(g, n, h, NULL, 1);
-           if (with_val && val) {
+           if (sym && val) {
                sprintf(buf, "%f", val[j]);
                agxset(e, sym, buf);
            }