From: Matthew Fernandez Date: Wed, 24 Feb 2021 02:06:19 +0000 (-0800) Subject: rewrite indexOf X-Git-Tag: 2.47.0~17^2~17 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=84efe93d5c5a4da0e778dbf01ed8550d2d774fdf;p=graphviz rewrite indexOf There is a C standard library function that does almost all of this for us. This removes two -Wconversion and one -Wsign-conversion warnings. --- diff --git a/lib/gvpr/actions.c b/lib/gvpr/actions.c index 47408870d..61f833afc 100644 --- a/lib/gvpr/actions.c +++ b/lib/gvpr/actions.c @@ -54,22 +54,8 @@ Agraph_t *sameG(void *p1, void *p2, char *fn, char *msg) */ int indexOf(char *s1, char *s2) { - char c1 = *s2; - char c; - char *p; - int len2; - - if (c1 == '\0') - return 0; - p = s1; - len2 = strlen(s2) - 1; - while ((c = *p++)) { - if (c != c1) - continue; - if (strncmp(p, s2 + 1, len2) == 0) - return ((p - s1) - 1); - } - return -1; + char *s = strstr(s1, s2); + return s == NULL ? -1 : (int)(s1 - s); } /* rindexOf: