Skip to content

Commit 0f4d37d

Browse files
authored
Enforce literals in certain macros (#10111)
These macros are designed only for literals. This is a standards compliant trick to ensure they are literals. For example, these are the same: "Hello" " world" "Hello world"
1 parent e628c66 commit 0f4d37d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Zend/zend_string.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,10 @@ static zend_always_inline bool zend_string_equals(const zend_string *s1, const z
371371
(ZSTR_LEN(s1) == ZSTR_LEN(s2) && !zend_binary_strcasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2)))
372372

373373
#define zend_string_equals_literal_ci(str, c) \
374-
(ZSTR_LEN(str) == sizeof(c) - 1 && !zend_binary_strcasecmp(ZSTR_VAL(str), ZSTR_LEN(str), (c), sizeof(c) - 1))
374+
(ZSTR_LEN(str) == sizeof("" c) - 1 && !zend_binary_strcasecmp(ZSTR_VAL(str), ZSTR_LEN(str), (c), sizeof(c) - 1))
375375

376376
#define zend_string_equals_literal(str, literal) \
377-
zend_string_equals_cstr(str, literal, strlen(literal))
377+
zend_string_equals_cstr(str, "" literal, sizeof(literal) - 1)
378378

379379
static zend_always_inline bool zend_string_starts_with_cstr(const zend_string *str, const char *prefix, size_t prefix_length)
380380
{

0 commit comments

Comments
 (0)