Skip to content

Commit 7b90ebe

Browse files
authored
Fix -Werror=sign-compare warning in zend_memnistr (#8042)
`error: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘long int’ [-Werror=sign-compare]` This is asserting `end >= haystack` as a precondition for callers (in debug builds) and existing callers are correct. An alternate option is to cast the left side to `int64_t`, but that may be slightly inefficient for 32-bit builds.
1 parent 0199b22 commit 7b90ebe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Zend/zend_operators.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,15 +939,15 @@ zend_memnistr(const char *haystack, const char *needle, size_t needle_len, const
939939
return haystack;
940940
}
941941

942-
if (UNEXPECTED(needle_len > (end - haystack))) {
942+
if (UNEXPECTED(needle_len > (size_t)(end - haystack))) {
943943
return NULL;
944944
}
945945

946946
const char first_lower = zend_tolower_ascii(*needle);
947947
const char first_upper = zend_toupper_ascii(*needle);
948948
const char *p_lower = (const char *)memchr(haystack, first_lower, end - haystack);
949949
const char *p_upper = NULL;
950-
if (first_lower != first_upper) {
950+
if (first_lower != first_upper) {
951951
// If the needle length is 1 we don't need to look beyond p_lower as it is a guaranteed match
952952
size_t upper_search_length = end - (needle_len == 1 && p_lower != NULL ? p_lower : haystack);
953953
p_upper = (const char *)memchr(haystack, first_upper, upper_search_length);

0 commit comments

Comments
 (0)