basic: replace size_multiply_overflow() with MUL_ASSIGN_SAFE where applicable

This commit is contained in:
Mike Yuan
2024-09-20 22:44:34 +02:00
parent 175de2c28e
commit 34fb408f8b
3 changed files with 23 additions and 25 deletions
+5 -6
View File
@@ -43,7 +43,7 @@ void* greedy_realloc(
size_t need,
size_t size) {
size_t a, newalloc;
size_t newalloc;
void *q;
assert(p);
@@ -60,14 +60,13 @@ void* greedy_realloc(
return NULL;
newalloc = need * 2;
if (size_multiply_overflow(newalloc, size))
if (!MUL_ASSIGN_SAFE(&newalloc, size))
return NULL;
a = newalloc * size;
if (a < 64) /* Allocate at least 64 bytes */
a = 64;
if (newalloc < 64) /* Allocate at least 64 bytes */
newalloc = 64;
q = realloc(*p, a);
q = realloc(*p, newalloc);
if (!q)
return NULL;