]> granicus.if.org Git - graphviz/commitdiff
rewrite indexOf
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 24 Feb 2021 02:06:19 +0000 (18:06 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 2 Mar 2021 06:05:11 +0000 (22:05 -0800)
There is a C standard library function that does almost all of this for us. This
removes two -Wconversion and one -Wsign-conversion warnings.

lib/gvpr/actions.c

index 47408870d2a06189b779a8f74ca8d84791f37131..61f833afc5a6bfe003441d3980a9e773acb80e9d 100644 (file)
@@ -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: