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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Looks like a regression only because the test is new.
I see the same code in there e.g. in GCC 3.2.

That said, I think we can do something like:
2019-02-25  Jakub Jelinek  <ja...@redhat.com>

        PR c++/89495
        * c-format.c (maybe_read_dollar_number): Compute nargnum in
        HOST_WIDE_INT type to avoid overflows and change overflow_flag
        checking.

--- gcc/c-family/c-format.c.jj  2019-01-16 09:35:04.565323073 +0100
+++ gcc/c-family/c-format.c     2019-02-25 16:26:07.872810237 +0100
@@ -1268,9 +1268,9 @@ maybe_read_dollar_number (const char **f
   overflow_flag = 0;
   while (ISDIGIT (*fcp))
     {
-      int nargnum;
-      nargnum = 10 * argnum + (*fcp - '0');
-      if (nargnum < 0 || nargnum / 10 != argnum)
+      HOST_WIDE_INT nargnum
+       = HOST_WIDE_INT_UC (10) * argnum + (*fcp - '0');
+      if ((int) nargnum != nargnum)
        overflow_flag = 1;
       argnum = nargnum;
       fcp++;

Reply via email to