From: Matthew Fernandez Date: Fri, 8 Jul 2022 00:24:05 +0000 (-0700) Subject: common textfont_comparf: rephrase comparator to avoid arithmetic X-Git-Tag: 5.0.1~32^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=948120fa23f91326f801a26a152fe3afa6497fcf;p=graphviz common textfont_comparf: rephrase comparator to avoid arithmetic cccb8b1d22a18031fc92d93133c7fa14ef7e1361 fixed an integer overflow in a `memcmp`-/`strcmp`-like comparator. The same situation exists in the code touched in this commit. Rather than wait for an edge case to expose an overflow here, this change makes the same update, removing arithmetic and the consequent possibility of overflow. --- diff --git a/lib/common/textspan.c b/lib/common/textspan.c index f9c60b259..dc54287c2 100644 --- a/lib/common/textspan.c +++ b/lib/common/textspan.c @@ -152,8 +152,8 @@ static int textfont_comparf (Dt_t* dt, void* key1, void* key2, Dtdisc_t* disc) rc = strcmp(f1->color, f2->color); if (rc) return rc; } - rc = (f1->flags - f2->flags); - if (rc) return rc; + if (f1->flags < f2->flags) return -1; + if (f1->flags > f2->flags) return 1; if (f1->size < f2->size) return -1; if (f1->size > f2->size) return 1; return 0;