We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4102c27 commit 21fc74bCopy full SHA for 21fc74b
main/reallocarray.c
@@ -22,20 +22,20 @@
22
23
PHPAPI void* php_reallocarray(void *p, size_t nmb, size_t siz)
24
{
25
-#ifndef _WIN32
26
size_t r;
+#ifndef _WIN32
27
if (__builtin_mul_overflow(nmb, siz, &r)) {
28
#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) {
+
+ r = siz * nmb;
+ if (siz != 0 && r / siz != nmb) {
32
#endif
33
// EOVERFLOW may have been, arguably, more appropriate
34
// but this is what other implementations set
35
errno = ENOMEM;
36
return NULL;
37
}
38
39
- return realloc(p, nmb * siz);
+ return realloc(p, r);
40
41
0 commit comments