From: Matthew Fernandez Date: Fri, 23 Dec 2022 03:04:58 +0000 (-0800) Subject: common scanEntity: use a more appropriate type for 'len' X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3a2456e7d3d7e4ac2a79f84bc61702d029687a52;p=graphviz common scanEntity: use a more appropriate type for 'len' 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. --- diff --git a/lib/common/utils.c b/lib/common/utils.c index 5e79b6a49..d0aed9a76 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -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;