public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Niklas Hambüchen" <mail@nh2.me>
To: DJ Delorie <dj@redhat.com>
Cc: libc-alpha@sourceware.org, schwab@linux-m68k.org
Subject: Re: [PATCH v2] malloc_stats(): Fix `unsigned int` overflow
Date: Tue, 14 Nov 2023 00:10:32 +0100	[thread overview]
Message-ID: <fc7ddfa0-4557-40f5-b925-9abcf3f39892@nh2.me> (raw)
In-Reply-To: <xn34x9qu33.fsf@greed.delorie.com>

> This needs a cast to (size_t) as max_mmapped_mem is INTERNAL_SIZE_T,
> which may be smaller than size_t.

Thanks, will fix!

>> +  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?

The non-`malloc_stats()` code that uses the `int` will likely also behave strangely if this overflow happens, so it seems weird to pretend the value is of a different type in the malloc-internals inspection function.

(Besides, `max_n_mmaps` sounds like a count of mmaps, not a byte count, so it should be much less likely to overflow.)

Thanks!

  reply	other threads:[~2023-11-13 23:10 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 [this message]
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=fc7ddfa0-4557-40f5-b925-9abcf3f39892@nh2.me \
    --to=mail@nh2.me \
    --cc=dj@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --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).