From: Emden Gansner Date: Wed, 3 May 2017 17:05:59 +0000 (-0400) Subject: Fix incorrect bsearch for colors. This basically rolls back the changes from X-Git-Tag: 2.42.0~177 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=27735a3c00757382ea353216b8598e83ea52e20c;p=graphviz Fix incorrect bsearch for colors. This basically rolls back the changes from e653d8054fe3c2313944a2a88f3ad7c374bd9b21 and a155276b30da0619979d0b7d5ae22cb05b9b7d16. --- diff --git a/lib/gvc/gvrender.c b/lib/gvc/gvrender.c index 57bbaf511..4b18aea05 100644 --- a/lib/gvc/gvrender.c +++ b/lib/gvc/gvrender.c @@ -183,6 +183,18 @@ pointf *gvrender_ptf_A(GVJ_t * job, pointf * af, pointf * AF, int n) return AF; } +static int gvrender_comparestr(const void *s1, const void *s2) +{ + return strcmp(*(char **) s1, *(char **) s2); +} + +/* gvrender_resolve_color: + * N.B. strcmp cannot be used in bsearch, as it will pass a pointer + * to an element in the array features->knowncolors (i.e., a char**) + * as an argument of the compare function, while the arguments to + * strcmp are both char*. Given this, the first argument to + * bsearch must also be char**, so we use &tok. + */ static void gvrender_resolve_color(gvrender_features_t * features, char *name, gvcolor_t * color) { @@ -195,8 +207,8 @@ static void gvrender_resolve_color(gvrender_features_t * features, if (!features->knowncolors || (bsearch - (tok, features->knowncolors, features->sz_knowncolors, - sizeof(char *), (int(*)(const void*, const void*)) strcmp)) == NULL) { + (&tok, features->knowncolors, features->sz_knowncolors, + sizeof(char *), gvrender_comparestr)) == NULL) { /* if tok was not found in known_colors */ rc = colorxlate(name, color, features->color_type); if (rc != COLOR_OK) {