public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gcc at pauldreik dot se" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/111162] New: signed integer overflow triggered by std::chrono::parse
Date: Sat, 26 Aug 2023 12:42:13 +0000	[thread overview]
Message-ID: <bug-111162-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 111162
           Summary: signed integer overflow triggered by
                    std::chrono::parse
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at pauldreik dot se
  Target Milestone: ---

The following program:

#include <chrono>
#include <format>
#include <sstream>
int main() {
    std::istringstream is("21474837");
    std::chrono::minutes x;
    is >> std::chrono::parse("%8C", x);
}

invokes undefined behaviour. If compiled with the current gcc trunk, one gets
this when executed:
/opt/compiler-explorer/gcc-trunk-20230824/include/c++/14.0.0/bits/chrono_io.h:3174:20:
runtime error: signed integer overflow: 21474837 * 100 cannot be represented in
type 'int'

link to reproducer (uses gcc trunk, may go stale quick):
https://godbolt.org/z/h617GT4EY

             reply	other threads:[~2023-08-26 12:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-26 12:42 gcc at pauldreik dot se [this message]
2023-08-26 13:52 ` [Bug libstdc++/111162] " redi at gcc dot gnu.org
2023-08-29 12:10 ` redi at gcc dot gnu.org
2023-09-01 10:55 ` cvs-commit at gcc dot gnu.org
2023-09-01 10:57 ` 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-111162-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).