remove use of int as size_t in rindexOf
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 24 Feb 2021 01:54:31 +0000 (17:54 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 2 Mar 2021 06:05:11 +0000 (22:05 -0800)
This removes two -Wconversion and one -Wsign-conversion warnings.

lib/gvpr/actions.c

index 61f833afc5a6bfe003441d3980a9e773acb80e9d..7b7566e944c1dd5663685c6fa322b50f53a9727a 100644 (file)
@@ -18,6 +18,7 @@
 #include <ast/ast.h>
 #include <gvpr/compile.h>
 #include <ast/sfstr.h>
+#include <stddef.h>
 #include <string.h>
 #include <stdio.h>
 #include <ctype.h>
@@ -66,11 +67,13 @@ int rindexOf(char *s1, char *s2)
     char c1 = *s2;
     char c;
     char *p;
-    int len1 = strlen(s1);
-    int len2 = strlen(s2);
+    size_t len1 = strlen(s1);
+    size_t len2 = strlen(s2);
 
     if (c1 == '\0')
        return (len1);
+    if (len2 > len1)
+       return -1;
     p = s1 + (len1 - len2);
     while (p >= s1) {
        c = *p;