From 948120fa23f91326f801a26a152fe3afa6497fcf Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Thu, 7 Jul 2022 17:24:05 -0700 Subject: [PATCH] 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. --- lib/common/textspan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; -- 2.40.0