Skip to content

Fix -Werror=sign-compare warning in zend_memnistr when compiling with -Werror #8042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Zend/zend_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -939,15 +939,15 @@ zend_memnistr(const char *haystack, const char *needle, size_t needle_len, const
return haystack;
}

if (UNEXPECTED(needle_len > (end - haystack))) {
if (UNEXPECTED(needle_len > (size_t)(end - haystack))) {
return NULL;
}

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