aboutsummaryrefslogtreecommitdiff
path: root/gcc/input.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2017-01-31 20:22:43 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2017-01-31 20:22:43 +0000
commit7cfa044d991a2622ca82c92b042ca06824994acd (patch)
tree08067378539cdf2cf09a589aa4ac65142975bfdb /gcc/input.c
parent5ae37bdfce3f433ff51af4d614d9271abb25671f (diff)
downloadgcc-7cfa044d991a2622ca82c92b042ca06824994acd.zip
gcc-7cfa044d991a2622ca82c92b042ca06824994acd.tar.gz
gcc-7cfa044d991a2622ca82c92b042ca06824994acd.tar.bz2
Prevent ICEs due to bogus substring locations (PR preprocessor/79210)
gcc/ChangeLog: PR preprocessor/79210 * input.c (get_substring_ranges_for_loc): Replace line_width assertion with error-handling. gcc/testsuite/ChangeLog: PR preprocessor/79210 * gcc.dg/format/pr79210.c: New test case. * gcc.dg/plugin/diagnostic-test-string-literals-2.c (test_pr79210): New function. From-SVN: r245070
Diffstat (limited to 'gcc/input.c')
-rw-r--r--gcc/input.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/gcc/input.c b/gcc/input.c
index 3e67314..38deb62 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -1395,7 +1395,10 @@ get_substring_ranges_for_loc (cpp_reader *pfile,
const char *literal = line + start.column - 1;
int literal_length = finish.column - start.column + 1;
- gcc_assert (line_width >= (start.column - 1 + literal_length));
+ /* Ensure that we don't crash if we got the wrong location. */
+ if (line_width < (start.column - 1 + literal_length))
+ return "line is not wide enough";
+
cpp_string from;
from.len = literal_length;
/* Make a copy of the literal, to avoid having to rely on