public inbox for
 help / color / mirror / Atom feed
From: Marco Falke <>
To: Marco Falke <>,,
Subject: Re: Re: [PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit
Date: Mon, 18 Jul 2022 12:10:31 +0200	[thread overview]
Message-ID: <> (raw)

[-- Attachment #1: Type: text/plain, Size: 923 bytes --]

(in reply to,
adding libstdc++ to CC, with the same patch attached again)

To clarify, this is not a fix for a user-facing issue of gcc or a fix
for UB. It is just a minor UX improvement for developers that use the
clang integer sanitizer to detect implicit int conversions.

To reproduce:

$ cat 1.cpp
#include <charconv>

int main() {
  const auto a{"-1"};
  unsigned b{};
  std::from_chars(a, a + 2, b);
$ clang++ -fsanitize=integer -std=c++17 1.cpp -o exe && ./exe
runtime error: implicit conversion from type 'int' of value -3
(32-bit, signed) to type 'unsigned char' changed the value to 253
(8-bit, unsigned)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior


[-- Attachment #2: 0001-libstdc-Make-__from_chars_alnum_to_val-conversion-ex.patch --]
[-- Type: text/x-patch, Size: 1244 bytes --]

From 2d4e7cd1d476a065d824e11045c8dbc049d5f0a0 Mon Sep 17 00:00:00 2001
From: MacroFake <>
Date: Thu, 14 Jul 2022 15:26:12 +0200
Subject: [PATCH] libstdc++: Make __from_chars_alnum_to_val conversion explicit

The optimizations from commit a54137c88061c7495728fc6b8dfd0474e812b2cb
introduced a clang integer sanitizer error.

Fix this with an explicit static_cast, similar to the fix in commit


        * include/std/charconv (__from_chars_alnum_to_val): Replace
          implicit conversions from int to unsigned char with explicit
 libstdc++-v3/include/std/charconv | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv
index 218813e4797..bdf23e4a5ad 100644
--- a/libstdc++-v3/include/std/charconv
+++ b/libstdc++-v3/include/std/charconv
@@ -436,7 +436,7 @@ namespace __detail
     __from_chars_alnum_to_val(unsigned char __c)
       if _GLIBCXX17_CONSTEXPR (_DecOnly)
-	return __c - '0';
+       return static_cast<unsigned char>(__c - '0');
 	  // This initializer is deliberately made dependent in order to work

             reply	other threads:[~2022-07-18 10:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-18 10:10 Marco Falke [this message]
2022-07-19 10:06 ` Jonathan Wakely
2022-07-19 10:13   ` Marco Falke
2022-07-19 10:15     ` Jonathan Wakely

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='' \ \ \ \

* 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).