From 94b0d63c995eacb54170b0ee2754d85ca1abfb21 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Tue, 5 Jul 2022 17:24:05 -0700 Subject: [PATCH] cgraph: rephrase ID comparison in 'agraphidcmpf' Avoids a possible integer overflow and squashes a -Wsign-conversion warning. --- lib/cgraph/graph.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 = { -- 2.40.0