From: Laszlo Ersek Date: Sun, 11 Sep 2022 12:32:37 +0000 (+0200) Subject: miniexpect.c: fix always-true comparison X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=783db67b0bf0ea3b10e842cbb210870a4947320e;p=miniexpect.git miniexpect.c: fix always-true comparison According to : > STRING LENGTHS AND OFFSETS > > The PCRE2 API uses string lengths and offsets into strings of code units > in several places. These values are always of type PCRE2_SIZE, which is > an unsigned integer type, currently always defined as size_t. The > largest value that can be stored in such a type (that is ~(PCRE2_SIZE)0) > is reserved as a special indicator for zero-terminated strings and unset > offsets. Therefore, the longest string that can be handled is one less > than this maximum. Therefore check the validity of ovector[1] with ovector[1] != ~(PCRE2_SIZE)0 rather than the always-true ovector[1] >= 0 This was caught by gcc's > miniexpect.c:359:45: warning: comparison of unsigned expression in ‘>= > 0’ is always true [-Wtype-limits] which is part of "-Wextra". Signed-off-by: Laszlo Ersek --- diff --git a/miniexpect.c b/miniexpect.c index 77d781c..8533514 100644 --- a/miniexpect.c +++ b/miniexpect.c @@ -356,7 +356,7 @@ mexp_expect (mexp_h *h, const mexp_regexp *regexps, if (match_data) ovector = pcre2_get_ovector_pointer (match_data); - if (ovector != NULL && ovector[1] >= 0) + if (ovector != NULL && ovector[1] != ~(PCRE2_SIZE)0) h->next_match = ovector[1]; else h->next_match = -1;