]> granicus.if.org Git - graphviz/commitdiff
gvpr rindexOf: return a long instead of int
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 28 Jul 2022 02:05:51 +0000 (19:05 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 2 Aug 2022 04:33:30 +0000 (21:33 -0700)
The only use of this function stores the return value in a long, so lets just
return a long, squashing two compiler warnings.

lib/gvpr/actions.c
lib/gvpr/actions.h

index 1040a9cebfd567e4034b19e86148f50a4c1569cd..6528d04219d53eef8721d5f14c300bbc4c04c58c 100644 (file)
@@ -18,6 +18,7 @@
 #include <ast/ast.h>
 #include <gvpr/compile.h>
 #include <ast/sfstr.h>
+#include <limits.h>
 #include <stddef.h>
 #include <string.h>
 #include <stdio.h>
@@ -63,15 +64,17 @@ int indexOf(char *s1, char *s2)
 /* rindexOf:
  * Return index of rightmost string s2 in string s1, or -1
  */
-int rindexOf(char *s1, char *s2)
+long rindexOf(char *s1, char *s2)
 {
     char c1 = *s2;
     char *p;
     size_t len1 = strlen(s1);
     size_t len2 = strlen(s2);
 
-    if (c1 == '\0')
-       return (len1);
+    if (c1 == '\0') {
+       assert(len1 <= LONG_MAX);
+       return (long)len1;
+    }
     if (len2 > len1)
        return -1;
     p = s1 + (len1 - len2);
index f7a2cb0916da0cb0bcc1a133effc2e8773881722..39dc117871b6191009008d48720b65c960b4f25b 100644 (file)
@@ -23,7 +23,7 @@ extern "C" {
     extern Agobj_t *copy(Agraph_t * g, Agobj_t * obj);
     extern int copyAttr(Agobj_t * obj, Agobj_t * obj1);
     extern int indexOf(char *s1, char *s2);
-    extern int rindexOf(char *s1, char *s2);
+    extern long rindexOf(char *s1, char *s2);
     extern int match(char *str, char *pat);
     extern int lockGraph(Agraph_t * g, int);
     extern Agraph_t *compOf(Agraph_t * g, Agnode_t * n);