public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
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 18:23:11 -0500	[thread overview]
Message-ID: <xnwmulp7a8.fsf@greed.delorie.com> (raw)
In-Reply-To: <fc7ddfa0-4557-40f5-b925-9abcf3f39892@nh2.me>

Niklas Hambchen <mail@nh2.me> writes:
>>> +  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.
>
> I'm not sure I understand:
> That statement holds for all `int`s, so following this logic, all
> `int`s should be casted to `unsigned int` first and printed with `%u`,
> and `%d` would be quite useless.
>
> Doesn't it make more sense to print an `int` with `%d` as normal, so
> that you can _see_ in `malloc_stats()` when it overflows?

It only really overflows when it wraps around 2^32.  Until then, the
value is still useful, as long as you present it properly.

An alternative would be to print out "(overflowed)" if the value exceeds 2^31

It just didn't seem right to take something that prints 0..2^32-1 and
reduce it to only print 0..2^31-1.

The other cases were stored as size_t and potentially truncated, which
is a different sort of overflow bug.


  reply	other threads:[~2023-11-13 23:23 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
2023-11-13 23:10           ` Niklas Hambüchen
2023-11-13 23:23             ` DJ Delorie [this message]
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=xnwmulp7a8.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).