public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "barry.revzin at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/101965] New: check in charconv is vacuously true
Date: Wed, 18 Aug 2021 18:19:52 +0000	[thread overview]
Message-ID: <bug-101965-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2021-08-18 18:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-18 18:19 barry.revzin at gmail dot com [this message]
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

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=bug-101965-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).