public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/101965] New: check in charconv is vacuously true
@ 2021-08-18 18:19 barry.revzin at gmail dot com
  2021-08-19 10:37 ` [Bug libstdc++/101965] " redi at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: barry.revzin at gmail dot com @ 2021-08-18 18:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101965

            Bug ID: 101965
           Summary: check in charconv is vacuously true
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

When investigating PVS-Studio in our codebase, it flagged this check in
charconv:

   322    template<typename _Tp>
   323      __detail::__integer_to_chars_result_type<_Tp>
   324      __to_chars_i(char* __first, char* __last, _Tp __value, int __base =
10)
   325      {
   326        __glibcxx_assert(2 <= __base && __base <= 36);
   327
   328        using _Up = __detail::__unsigned_least_t<_Tp>;
   329        _Up __unsigned_val = __value;
   330
   331        if (__first == __last) [[__unlikely__]]
   332          return { __last, errc::value_too_large };
   333
   334        if (__value == 0)
   335          {
   336            *__first = '0';
   337            return { __first + 1, errc{} };
   338          }
   339
   340        if _GLIBCXX17_CONSTEXPR (std::is_signed<_Tp>::value)
   341          if (__value < 0)
   342            {
   343              if (__builtin_expect(__first != __last, 1))
   344                *__first++ = '-';
   345              __unsigned_val = _Up(~__value) + _Up(1);
   346            }
   347
   348        switch (__base)
   349        {
   350        case 16:

On line 343, __first is never equal to __last. If it were, we would've returned
on line 332.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-11-26 17:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18 18:19 [Bug libstdc++/101965] New: check in charconv is vacuously true barry.revzin at gmail dot com
2021-08-19 10:37 ` [Bug libstdc++/101965] " redi at gcc dot gnu.org
2021-08-19 10:38 ` redi at gcc dot gnu.org
2021-08-19 13:57 ` cvs-commit at gcc dot gnu.org
2021-08-19 14:10 ` redi at gcc dot gnu.org
2021-08-24 16:01 ` cvs-commit at gcc dot gnu.org
2021-11-26 16:35 ` cvs-commit at gcc dot gnu.org
2021-11-26 17:30 ` redi at gcc dot gnu.org

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