]> granicus.if.org Git - graphviz/commitdiff
smyrna object_color: rephrase to make initialization of 'vis' more obvious
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 10 Sep 2021 04:24:36 +0000 (21:24 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 16 Sep 2021 04:31:00 +0000 (21:31 -0700)
Auditing all call sites of this function reveals it is only ever called with
edges and nodes. But the compiler could not see enough to know this. On macOS,
Clang dutifully warns:

  topviewfuncs.c:165:13: warning: variable 'vis' is used uninitialized whenever
    'if' condition is false [-Wsometimes-uninitialized]

as noted by Stephen.¹

¹ https://forum.graphviz.org/t/tracking-down-warnings-old-news-to-some-of-you/821

cmd/smyrna/topviewfuncs.c

index 3c9207784181f17e21321407ef78dd96addf41e8..4c1ec7ab8f5cf264963e1a184d12658a3b7a5c26 100644 (file)
@@ -8,6 +8,7 @@
  * Contributors: Details at https://graphviz.org
  *************************************************************************/
 
+#include <assert.h>
 #include "topviewfuncs.h"
 #include <cgraph/cgraph.h>
 #include "smyrna_utils.h"
@@ -162,7 +163,8 @@ static int object_color(void* obj,glCompColor* c)
        Alpha=getAttrFloat(g,objg,"defaultedgealpha",1);
        vis = GE_visible (objg);
     }
-    else if(objType==AGNODE) {
+    else {
+       assert(objType == AGNODE);
        Alpha=getAttrFloat(g,objg,"defaultnodealpha",1);
        vis = GN_visible (objg);
     }