Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libbsdmalloc libbsdmalloc: Use a multiply-overflow that ...



details:   https://anonhg.NetBSD.org/src/rev/85462f287c08
branches:  trunk
changeset: 377299:85462f287c08
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Jul 05 22:13:20 2023 +0000

description:
libbsdmalloc: Use a multiply-overflow that clang supports too.

XXX pullup-10

diffstat:

 lib/libbsdmalloc/malloc.c |  7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diffs (31 lines):

diff -r 0a4a1f1ceae1 -r 85462f287c08 lib/libbsdmalloc/malloc.c
--- a/lib/libbsdmalloc/malloc.c Wed Jul 05 16:41:12 2023 +0000
+++ b/lib/libbsdmalloc/malloc.c Wed Jul 05 22:13:20 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: malloc.c,v 1.8 2023/07/05 12:08:49 riastradh Exp $     */
+/*     $NetBSD: malloc.c,v 1.9 2023/07/05 22:13:20 riastradh Exp $     */
 
 /*
  * Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)malloc.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: malloc.c,v 1.8 2023/07/05 12:08:49 riastradh Exp $");
+__RCSID("$NetBSD: malloc.c,v 1.9 2023/07/05 22:13:20 riastradh Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -546,11 +546,10 @@ calloc(size_t nmemb, size_t size)
        void *p;
        size_t n;
 
-       if (__builtin_mul_overflow_p(nmemb, size, (size_t)0)) {
+       if (__builtin_mul_overflow(nmemb, size, &n)) {
                errno = ENOMEM;
                return NULL;
        }
-       n = nmemb * size;
        p = malloc(n);
        if (__predict_false(p == NULL))
                return NULL;



Home | Main Index | Thread Index | Old Index