Skip to content

Commit 21fc74b

Browse files
committed
changes from feedback
1 parent 4102c27 commit 21fc74b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

main/reallocarray.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
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+
r = siz * nmb;
31+
if (siz != 0 && r / siz != nmb) {
3232
#endif
3333
// EOVERFLOW may have been, arguably, more appropriate
3434
// but this is what other implementations set
3535
errno = ENOMEM;
3636
return NULL;
3737
}
3838

39-
return realloc(p, nmb * siz);
39+
return realloc(p, r);
4040
}
4141
#endif

0 commit comments

Comments
 (0)