From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Do not use std::isdigit in <charconv> [PR103911]
Date: Thu, 6 Jan 2022 14:57:25 +0000 [thread overview]
Message-ID: <20220106145725.1932037-1-jwakely@redhat.com> (raw)
Tested powerpc64le-linux, pushed to trunk.
This avoids a potential race condition if std::setlocale is used
concurrently with std::from_chars.
libstdc++-v3/ChangeLog:
PR libstdc++/103911
* include/std/charconv (__from_chars_alpha_to_num): Return
char instead of unsigned char. Change invalid return value to
127 instead of using numeric trait.
(__from_chars_alnum): Fix comment. Do not use std::isdigit.
Change type of variable to char.
---
libstdc++-v3/include/std/charconv | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv
index 4337a9e52f9..a3f8c7718b2 100644
--- a/libstdc++-v3/include/std/charconv
+++ b/libstdc++-v3/include/std/charconv
@@ -39,7 +39,6 @@
#include <type_traits>
#include <bit> // for __bit_width
-#include <cctype> // for isdigit
#include <bits/charconv.h> // for __to_chars_len, __to_chars_10_impl
#include <bits/error_constants.h> // for std::errc
#include <ext/numeric_traits.h>
@@ -466,7 +465,7 @@ namespace __detail
return true;
}
- constexpr unsigned char
+ constexpr char
__from_chars_alpha_to_num(char __c)
{
switch (__c)
@@ -550,10 +549,10 @@ namespace __detail
case 'Z':
return 35;
}
- return __gnu_cxx::__int_traits<unsigned char>::__max;
+ return 127;
}
- /// std::from_chars implementation for integers in bases 11 to 26.
+ /// std::from_chars implementation for integers in bases 11 to 36.
template<typename _Tp>
bool
__from_chars_alnum(const char*& __first, const char* __last, _Tp& __val,
@@ -562,8 +561,8 @@ namespace __detail
bool __valid = true;
while (__first != __last)
{
- unsigned char __c = *__first;
- if (std::isdigit(__c))
+ char __c = *__first;
+ if ('0' <= __c && __c <= '9') // isdigit
__c -= '0';
else
{
--
2.31.1
reply other threads:[~2022-01-06 14:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220106145725.1932037-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.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).