From: "Niklas Hambüchen" <mail@nh2.me>
To: libc-alpha@sourceware.org
Subject: [PATCH] malloc_stats(): Fix `unsigned int` overflow
Date: Fri, 29 Oct 2021 19:11:34 +0200 [thread overview]
Message-ID: <e32ab95a-39f8-4536-acc9-b9b87ebaa996@nh2.me> (raw)
Fixes malloc_stats() returning vastly wrong information for programs
that use more than 2 GiB memory.
`man mallinfo` documents that it uses `int` and wraps around, but
`man malloc_stats` does not, and should not.
Fixes https://sourceware.org/bugzilla/show_bug.cgi?id=21556
Signed-off-by: Niklas Hambüchen <mail@nh2.me>
---
malloc/malloc.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 095d97a3be..cdc9aff9d5 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -5151,7 +5151,7 @@ __malloc_stats (void)
{
int i;
mstate ar_ptr;
- unsigned int in_use_b = mp_.mmapped_mem, system_b = in_use_b;
+ size_t in_use_b = mp_.mmapped_mem, system_b = in_use_b;
if (!__malloc_initialized)
ptmalloc_init ();
@@ -5166,8 +5166,8 @@ __malloc_stats (void)
__libc_lock_lock (ar_ptr->mutex);
int_mallinfo (ar_ptr, &mi);
fprintf (stderr, "Arena %d:\n", i);
- fprintf (stderr, "system bytes = %10u\n", (unsigned int) mi.arena);
- fprintf (stderr, "in use bytes = %10u\n", (unsigned int) mi.uordblks);
+ fprintf (stderr, "system bytes = %10lu\n", mi.arena);
+ fprintf (stderr, "in use bytes = %10lu\n", mi.uordblks);
#if MALLOC_DEBUG > 1
if (i > 0)
dump_heap (heap_for_ptr (top (ar_ptr)));
@@ -5180,9 +5180,9 @@ __malloc_stats (void)
break;
}
fprintf (stderr, "Total (incl. mmap):\n");
- fprintf (stderr, "system bytes = %10u\n", system_b);
- fprintf (stderr, "in use bytes = %10u\n", in_use_b);
- fprintf (stderr, "max mmap regions = %10u\n", (unsigned int) mp_.max_n_mmaps);
+ fprintf (stderr, "system bytes = %10lu\n", system_b);
+ fprintf (stderr, "in use bytes = %10lu\n", in_use_b);
+ fprintf (stderr, "max mmap regions = %10d\n", mp_.max_n_mmaps);
fprintf (stderr, "max mmap bytes = %10lu\n",
(unsigned long) mp_.max_mmapped_mem);
stderr->_flags2 = old_flags2;
--
2.31.1
next reply other threads:[~2021-10-29 17:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-29 17:11 Niklas Hambüchen [this message]
2021-10-29 19:50 ` DJ Delorie
2021-10-30 0:36 ` Niklas Hambüchen
2021-10-30 1:39 ` Siddhesh Poyarekar
2021-10-30 6:55 ` Andreas Schwab
2023-11-13 18:27 ` [PATCH v2] " Niklas Hambüchen
2023-11-13 20:25 ` DJ Delorie
2023-11-13 23:10 ` Niklas Hambüchen
2023-11-13 23:23 ` DJ Delorie
2021-11-01 12:34 ` [PATCH] " Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e32ab95a-39f8-4536-acc9-b9b87ebaa996@nh2.me \
--to=mail@nh2.me \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).