]> granicus.if.org Git - graphviz/commitdiff
common scanEntity: use a more appropriate type for 'len'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 23 Dec 2022 03:04:58 +0000 (19:04 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 24 Dec 2022 18:48:38 +0000 (10:48 -0800)
This addresses a problem where the subtraction of two pointers, `endp - t`, can
in theory exceed the size of an `int`. In practice this cannot occur, but using
a more correct type squashes a -Wconversion and -Wsign-conversion warning in
this code.

lib/common/utils.c

index 5e79b6a491995aef4a84bc177687f8c7611640e5..d0aed9a7649822a451cabe4668da0ee66385f2ab 100644 (file)
@@ -1257,12 +1257,12 @@ char* scanEntity (char* t, agxbuf* xb)
 {
     char*  endp = strchr (t, ';');
     struct entities_s key, *res;
-    int    len;
+    size_t len;
     char   buf[MAXENTLEN+1];
 
     agxbputc(xb, '&');
     if (!endp) return t;
-    if (((len = endp-t) > MAXENTLEN) || (len < 2)) return t;
+    if (((len = (size_t)(endp - t)) > MAXENTLEN) || (len < 2)) return t;
     strncpy (buf, t, len);
     buf[len] = '\0';
     key.name =  buf;