From ceaae49b2d7b935f849f065c4ec2e9d3537c9e1b Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 23 May 2021 11:46:37 +0200 Subject: [PATCH] tweaks: avoid the subtraction of two size_t variables becoming negative This fixes https://savannah.gnu.org/bugs/?60658. Found by compiling with -fsanitize=undefined. --- src/chars.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chars.c b/src/chars.c index 5122401d..e733f6f4 100644 --- a/src/chars.c +++ b/src/chars.c @@ -540,7 +540,7 @@ char *mbrevstrcasestr(const char *haystack, const char *needle, size_t tail_len = mbstrlen(pointer); if (tail_len < needle_len) - pointer += tail_len - needle_len; + pointer -= (needle_len - tail_len); if (pointer < haystack) return NULL;