Skip to content

Commit 1bdd07e

Browse files
committed
changes from feedback
1 parent 4102c27 commit 1bdd07e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

main/reallocarray.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222

2323
PHPAPI void* php_reallocarray(void *p, size_t nmb, size_t siz)
2424
{
25-
#ifndef _WIN32
2625
size_t r;
26+
#ifndef _WIN32
2727
if (__builtin_mul_overflow(nmb, siz, &r)) {
2828
#else
29-
// nmb an siz must be lower than sqrt SIZE_MAX+1
30-
static size_t elim = 1UL << (sizeof(size_t) * CHAR_BIT / 2);
31-
if ((nmb >= elim || siz >= elim) && nmb > 0 && SIZE_MAX / nmb < siz) {
29+
30+
// nmb and siz must be lower than sqrt SIZE_MAX+1
31+
r = siz * nmb;
32+
if (siz != 0 && r / siz != nmb) {
3233
#endif
3334
// EOVERFLOW may have been, arguably, more appropriate
3435
// but this is what other implementations set

0 commit comments

Comments
 (0)