From: Jeffrey Walton <noloader@gmail.com>
To: musl@lists.openwall.com
Cc: Michal Terepeta <michalt@google.com>,
t5y-external <t5y-external@google.com>
Subject: Re: Wrong formatting of doubles?
Date: Tue, 1 Jul 2025 13:02:44 -0400 [thread overview]
Message-ID: <CAH8yC8=kmYz+WGWMmqWZ8psv_tQ9dUk1ai1qWXkswMVPKiXytA@mail.gmail.com> (raw)
In-Reply-To: <20250701163758.GD1827@brightrain.aerifal.cx>
On Tue, Jul 1, 2025 at 12:38 PM Rich Felker <dalias@libc.org> wrote:
>
> > > On Tue, Jul 01, 2025 at 07:55:20AM +0200, Michal Terepeta wrote:
> > > > Hi,
> > > >
> > > > We're working on a RISC-V system and using musl as our libc. A recent change
> > > > in musl seems to have caused wrong formatting (printf) of double values:
> > > > https://git.musl-libc.org/cgit/musl/commit/src/stdio/vfprintf.c?id=572a2e2eb91f00f2f25d301cfb50f435e7ae16b3
> > > > [...]
> [...]
> I'd also like to think about ways we could avoid introducing bugs like
> this in the future. In this case, just a testcase for printing DBL_MAX
> in multiple formats would likely have caught it. Simple trapping-only
> UBsan might have caught it, but I'm not sure if that would follow all
> the positional arithmetic in fmt_fp to detect going outside the object
> bounds. This may be worth investigating.
Yes, test cases under a tool like a memory checker or UB checker are
the way to go. In this case, the sanitizers or Valgrind likely would
have alerted to the problematic code.
Another trick I like to use in debug builds is the use of asserts to
verify all program state. In this case, you might be able to check if
a pointer is within a particular range. In release builds, the checks
can be omitted since they were already verified using a test case in
debug builds, so the code will not take a performance hit.
When I perform root cause analysis on why a bug hit production, it
just about always (always?) includes a missing test case.
Jeff
next prev parent reply other threads:[~2025-07-01 17:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-01 5:55 Wrong formatting of doubles? Michal Terepeta
2025-07-01 14:22 ` [musl] " Rich Felker
2025-07-01 16:19 ` Rich Felker
2025-07-01 16:37 ` Rich Felker
2025-07-01 17:02 ` Jeffrey Walton [this message]
2025-07-01 17:22 ` [musl] " Markus Wichmann
2025-07-01 17:34 ` Rich Felker
2025-07-02 1:46 ` Rich Felker
2025-07-02 7:56 ` [musl] " Michal Terepeta
2025-07-08 7:43 ` Michal Terepeta
2025-07-08 16:22 ` [musl] " Rich Felker
2025-07-02 14:58 ` Rich Felker
2025-07-03 4:31 ` Markus Wichmann
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='CAH8yC8=kmYz+WGWMmqWZ8psv_tQ9dUk1ai1qWXkswMVPKiXytA@mail.gmail.com' \
--to=noloader@gmail.com \
--cc=michalt@google.com \
--cc=musl@lists.openwall.com \
--cc=t5y-external@google.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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 NNTP newsgroup(s).