From: Matthew Fernandez Date: Wed, 6 Jul 2022 00:24:05 +0000 (-0700) Subject: cgraph: rephrase ID comparison in 'agraphidcmpf' X-Git-Tag: 5.0.1~46^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=94b0d63c995eacb54170b0ee2754d85ca1abfb21;p=graphviz cgraph: rephrase ID comparison in 'agraphidcmpf' Avoids a possible integer overflow and squashes a -Wsign-conversion warning. --- diff --git a/lib/cgraph/graph.c b/lib/cgraph/graph.c index 1e2223a4d..a2f1aacb2 100644 --- a/lib/cgraph/graph.c +++ b/lib/cgraph/graph.c @@ -239,11 +239,15 @@ static int agraphidcmpf(Dict_t * d, void *arg0, void *arg1, Dtdisc_t * disc) { (void)d; /* unused */ (void)disc; /* unused */ - ptrdiff_t v; Agraph_t *sg0 = arg0; Agraph_t *sg1 = arg1; - v = (AGID(sg0) - AGID(sg1)); - return ((v==0)?0:(v<0?-1:1)); + if (AGID(sg0) < AGID(sg1)) { + return -1; + } + if (AGID(sg0) > AGID(sg1)) { + return 1; + } + return 0; } Dtdisc_t Ag_subgraph_id_disc = {