diff options
author | Joseph Myers <joseph@codesourcery.com> | 2020-11-27 22:40:01 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2020-11-27 22:40:01 +0000 |
commit | 9ccffd1298b5235b25ad05b89e3104fb2935fe27 (patch) | |
tree | cf825ab7f1747bd8cc89e4583b7e8585ddc2b0ea /gcc | |
parent | 5dbab7b3f4d3a8298aeb8ecde1cfbc4b16913d28 (diff) | |
download | gcc-9ccffd1298b5235b25ad05b89e3104fb2935fe27.zip gcc-9ccffd1298b5235b25ad05b89e3104fb2935fe27.tar.gz gcc-9ccffd1298b5235b25ad05b89e3104fb2935fe27.tar.bz2 |
preprocessor: Fix #line overflow check [PR97602]
The preprocessor check for overflow (of linenum_type = unsigned int)
when reading the line number in a #line directive is incomplete; it
checks "reg < reg_prev" which doesn't cover all cases where
multiplying by 10 overflowed. Fix this by checking for overflow
before rather than after it occurs (using essentially the same logic
as used by e.g. glibc printf when reading width and precision values
from strings).
Bootstrapped with no regressions for x86_64-pc-linux-gnu.
libcpp/
2020-11-27 Joseph Myers <joseph@codesourcery.com>
PR preprocessor/97602
* directives.c (strtolinenum): Check for overflow before it
occurs. Correct comment.
gcc/testsuite/
2020-11-27 Joseph Myers <joseph@codesourcery.com>
PR preprocessor/97602
* gcc.dg/cpp/line9.c, gcc.dg/cpp/line10.c: New tests.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/line10.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/line9.c | 5 |
2 files changed, 10 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/cpp/line10.c b/gcc/testsuite/gcc.dg/cpp/line10.c new file mode 100644 index 0000000..9f5f079 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/line10.c @@ -0,0 +1,5 @@ +/* Test #line overflow checks: bug 97602. */ +/* { dg-do preprocess } */ +/* { dg-options "-pedantic" } */ + +#line 4294967296 /* { dg-warning "line number out of range" } */ diff --git a/gcc/testsuite/gcc.dg/cpp/line9.c b/gcc/testsuite/gcc.dg/cpp/line9.c new file mode 100644 index 0000000..8060aff --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/line9.c @@ -0,0 +1,5 @@ +/* Test #line overflow checks: bug 97602. */ +/* { dg-do preprocess } */ +/* { dg-options "-pedantic" } */ + +#line 5000000000 /* { dg-warning "line number out of range" } */ |