From ec384a3408022c4d5f35f19d0b540dbfb7b061dd Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Wed, 29 Sep 2021 20:29:01 -0700 Subject: [PATCH] fix GVPR incorrect interpretation of color strings 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 | 1 + lib/gvpr/actions.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00b6a6a77..cb9e470e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/gvpr/actions.c b/lib/gvpr/actions.c index 97d58bb8a..4c941c58b 100644 --- a/lib/gvpr/actions.c +++ b/lib/gvpr/actions.c @@ -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 '/' */ -- 2.40.0