Skip to content

Commit 937d5f6

Browse files
committed
Compute needle end only after checking it's non-empty
1 parent 8cefd7c commit 937d5f6

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
@@ -148,7 +148,6 @@ static zend_always_inline const char *
148148
zend_memnstr(const char *haystack, const char *needle, size_t needle_len, const char *end)
149149
{
150150
const char *p = haystack;
151-
const char ne = needle[needle_len-1];
152151
ptrdiff_t off_p;
153152
size_t off_s;
154153

@@ -168,6 +167,7 @@ zend_memnstr(const char *haystack, const char *needle, size_t needle_len, const
168167
}
169168

170169
if (EXPECTED(off_s < 1024 || needle_len < 9)) { /* glibc memchr is faster when needle is too short */
170+
const char ne = needle[needle_len-1];
171171
end -= needle_len;
172172

173173
while (p <= end) {
@@ -210,7 +210,6 @@ static zend_always_inline const char *
210210
zend_memnrstr(const char *haystack, const char *needle, size_t needle_len, const char *end)
211211
{
212212
const char *p = end;
213-
const char ne = needle[needle_len-1];
214213
ptrdiff_t off_p;
215214
size_t off_s;
216215

@@ -230,6 +229,7 @@ zend_memnrstr(const char *haystack, const char *needle, size_t needle_len, const
230229
}
231230

232231
if (EXPECTED(off_s < 1024 || needle_len < 3)) {
232+
const char ne = needle[needle_len-1];
233233
p -= needle_len;
234234

235235
do {

0 commit comments

Comments
 (0)