]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/89495 (gcc/c-family/c-format.c:1272:20: runtime error: signed integer overflo...
authorJakub Jelinek <jakub@redhat.com>
Mon, 25 Feb 2019 23:43:51 +0000 (00:43 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 25 Feb 2019 23:43:51 +0000 (00:43 +0100)
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.

From-SVN: r269198

gcc/c-family/ChangeLog
gcc/c-family/c-format.c

index 951231efaac739c633f42db5cd915cff1b877d83..72d4fd2bfc55e28497d4e6359b44750d8d5e414a 100644 (file)
@@ -1,3 +1,10 @@
+2019-02-25  Jakub Jelinek  <jakub@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.
+
 2019-02-22  Richard Biener  <rguenther@suse.de>
 
        * c-pch.c (no_checksum): Remove.
index 9b48ee3e3f4fba4f39fe9ab71d547b4c743d6f68..a7f76c1c01d043eca592c99ab48eaecb94cc3d15 100644 (file)
@@ -1268,9 +1268,9 @@ maybe_read_dollar_number (const char **format,
   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++;