]> granicus.if.org Git - graphviz/commitdiff
fix GVPR incorrect interpretation of color strings
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 30 Sep 2021 03:29:01 +0000 (20:29 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 2 Oct 2021 01:14:21 +0000 (18:14 -0700)
The logical operators here were pretty clearly meant to be `&&` not `||`. But
this kind of micro-optimization is unnecessary on modern machines anyway, so we
can just rewrite this into something that is more obvious for both readers and
the compiler.

It would have been nice to add a provoking test case for this as well, but it is
not clear to me how exactly to reach this path. This bug has been open for quite
a while, so it seems simpler to apply the obvious fix and move on.

Fixes #1956.

CHANGELOG.md
lib/gvpr/actions.c

index 00b6a6a7741da6e25fa53515f40821eff1484b6f..cb9e470e69b906b90a5d0f1888f86d4957cd4f92 100644 (file)
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Msys experimental packages are included in release artifacts #2130
 - CMake build system incorrectly aliases gv2gml to gml2gv #2131
 - Gv2gml Doesn't escape quotes in attributes #1276
+- GVPR incorrectly understands color schemes #1956
 
 ## [2.49.1] – 2021-09-22
 
index 97d58bb8a77805a0065272660ef9fa466b82e36e..4c941c58ba9c9c4e5a78cd5be15496f03ecbc4bf 100644 (file)
@@ -998,9 +998,9 @@ static char* resolveColor (char* str)
     char* ss;   /* second slash */
     char* c2;   /* second char */
 
-    if ((*str == 'b') || !strncmp(str+1,"lack",4)) return str;
-    if ((*str == 'w') || !strncmp(str+1,"hite",4)) return str;
-    if ((*str == 'l') || !strncmp(str+1,"ightgrey",8)) return str;
+    if (strncmp(str, "black", strlen("black")) == 0) return str;
+    if (strncmp(str, "white", strlen("white")) == 0) return str;
+    if (strncmp(str, "lightgrey", strlen("lightgrey")) == 0) return str;
     if (*str == '/') {   /* if begins with '/' */
        c2 = str+1;
         if ((ss = strchr(c2, '/'))) {  /* if has second '/' */