summaryrefslogtreecommitdiff
path: root/tools/include/nolibc/stdlib.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2022-08-02 19:22:24 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2022-08-02 19:22:24 -0700
commitb069122256e45216b5c49d9441f9713991a4c645 (patch)
tree6a571f24e85308711234d5cec4604c9669198aee /tools/include/nolibc/stdlib.h
parent7d9d077c783e33995c80d8b28fea1a98161934f4 (diff)
parent4f8126f3a665456b68ae923cd7a7e9b9eb98547d (diff)
downloadlinux-b069122256e45216b5c49d9441f9713991a4c645.tar.gz
linux-b069122256e45216b5c49d9441f9713991a4c645.tar.bz2
linux-b069122256e45216b5c49d9441f9713991a4c645.zip
Merge tag 'nolibc.2022.07.27a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu
Pull nolibc updates from Paul McKenney: "This provides nolibc updates, perhaps most notably improved testing via the 'cd tools/include/nolibc; make headers' command. This should be considered a smoke test. More thorough testing is in the works" * tag 'nolibc.2022.07.27a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu: tools/nolibc: add a help target to list supported targets tools/nolibc: make the default target build the headers tools/nolibc: fix the makefile to also work as "make -C tools ..." tools/nolibc/stdio: Add format attribute to enable printf warnings tools/nolibc/stdlib: Support overflow checking for older compiler versions
Diffstat (limited to 'tools/include/nolibc/stdlib.h')
-rw-r--r--tools/include/nolibc/stdlib.h7
1 files changed, 3 insertions, 4 deletions
diff --git a/tools/include/nolibc/stdlib.h b/tools/include/nolibc/stdlib.h
index 8fd32eaf8037..92378c4b9660 100644
--- a/tools/include/nolibc/stdlib.h
+++ b/tools/include/nolibc/stdlib.h
@@ -128,10 +128,9 @@ void *malloc(size_t len)
static __attribute__((unused))
void *calloc(size_t size, size_t nmemb)
{
- void *orig;
- size_t res = 0;
+ size_t x = size * nmemb;
- if (__builtin_expect(__builtin_mul_overflow(nmemb, size, &res), 0)) {
+ if (__builtin_expect(size && ((x / size) != nmemb), 0)) {
SET_ERRNO(ENOMEM);
return NULL;
}
@@ -140,7 +139,7 @@ void *calloc(size_t size, size_t nmemb)
* No need to zero the heap, the MAP_ANONYMOUS in malloc()
* already does it.
*/
- return malloc(res);
+ return malloc(x);
}
static __attribute__((unused))