From 7da73ba7ef0e48d756677d17b8addc4f4fe2a484 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 26 Feb 2019 00:43:51 +0100 Subject: [PATCH] re PR c/89495 (gcc/c-family/c-format.c:1272:20: runtime error: signed integer overflow: 214748365 * 10 cannot be represented in type 'int') 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 | 7 +++++++ gcc/c-family/c-format.c | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 951231efaac..72d4fd2bfc5 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,10 @@ +2019-02-25 Jakub Jelinek + + 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 * c-pch.c (no_checksum): Remove. diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c index 9b48ee3e3f4..a7f76c1c01d 100644 --- a/gcc/c-family/c-format.c +++ b/gcc/c-family/c-format.c @@ -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++; -- 2.30.2