From: DJ Delorie <dj@redhat.com>
To: "Niklas Hambüchen" <mail@nh2.me>
Cc: libc-alpha@sourceware.org, schwab@linux-m68k.org
Subject: Re: [PATCH v2] malloc_stats(): Fix `unsigned int` overflow
Date: Mon, 13 Nov 2023 15:25:20 -0500 [thread overview]
Message-ID: <xn34x9qu33.fsf@greed.delorie.com> (raw)
In-Reply-To: <d5201ee6-ee91-4430-8c20-e1d3d36b7f13@nh2.me>
Niklas Hambchen <mail@nh2.me> writes:
> @@ -5374,7 +5374,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;
Ok.
> @@ -5389,8 +5389,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 = %10zu\n", mi.arena);
> + fprintf (stderr, "in use bytes = %10zu\n", mi.uordblks);
Ok.
> - fprintf (stderr, "system bytes = %10u\n", system_b);
> - fprintf (stderr, "in use bytes = %10u\n", in_use_b);
> - fprintf (stderr, "max mmap bytes = %10lu\n",
> - (unsigned long) mp_.max_mmapped_mem);
> + fprintf (stderr, "system bytes = %10zu\n", system_b);
> + fprintf (stderr, "in use bytes = %10zu\n", in_use_b);
> + fprintf (stderr, "max mmap bytes = %10zu\n", mp_.max_mmapped_mem);
This needs a cast to (size_t) as max_mmapped_mem is INTERNAL_SIZE_T,
which may be smaller than size_t.
> - fprintf (stderr, "max mmap regions = %10u\n", (unsigned int) mp_.max_n_mmaps);
> + fprintf (stderr, "max mmap regions = %10d\n", mp_.max_n_mmaps);
This causes a negative number to be printed when max_n_mmaps increments
past 2^31, where using "u" defers bad results until 2^32. So IMHO this
one is a regression, not a fix.
next prev parent reply other threads:[~2023-11-13 20:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-29 17:11 [PATCH] " Niklas Hambüchen
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 [this message]
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=xn34x9qu33.fsf@greed.delorie.com \
--to=dj@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=mail@nh2.me \
--cc=schwab@linux-m68k.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).