summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/include/nolibc/stdlib.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h
index 2113a8e7695d..1816c2368b68 100644
--- a/tools/include/nolibc/stdlib.h
+++ b/tools/include/nolibc/stdlib.h
@@ -145,9 +145,9 @@ void *malloc(size_t len)
static __attribute__((unused))
void *calloc(size_t size, size_t nmemb)
{
- size_t x = size * nmemb;
+ size_t x;
- if (__builtin_expect(size && ((x / size) != nmemb), 0)) {
+ if (__builtin_expect(__builtin_mul_overflow(size, nmemb, &x), 0)) {
SET_ERRNO(ENOMEM);
return NULL;
}