aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@gcc.gnu.org>2017-07-13 19:30:42 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2017-07-13 19:30:42 +0000
commit338d6484d186c86d64d6c551fdeeb5ae9df5a316 (patch)
tree96c0f0573a7aa2751ad412eec2875d1bf5ba43bf /gcc/gcc.c
parent1260d19905063540e560bda4924f09f1aff4bed5 (diff)
downloadgcc-338d6484d186c86d64d6c551fdeeb5ae9df5a316.zip
gcc-338d6484d186c86d64d6c551fdeeb5ae9df5a316.tar.gz
gcc-338d6484d186c86d64d6c551fdeeb5ae9df5a316.tar.bz2
diagnostics: fix crash when consolidating out-of-order fix-it hints (PR c/81405)
PR c/81405 identifies a crash when printing fix-it hints from -Wmissing-braces when there are excess elements. The fix-it hints are bogus (which I've filed separately as PR c/81432), but they lead to a crash within the fix-it consolidation logic I added in r247548, in line_corrections::add_hint. The root cause is that some of the fix-it hints are out-of-order with respect to the column numbers they affect, which can lead to negative values when computing the gap between the fix-it hints, leading to bogus memcpy calls that generate out-of-bounds buffer accesses. The fix is to sort the fix-it hints after filtering them, ensuring that the gap >= 0. The patch also adds numerous assertions to the code, both directly, and by moving the memcpy calls and their args behind interfaces (themselves containing gcc_assert). This fixes the crash; it doesn't fix the bug in -Wmissing-braces that leads to the bogus hints. gcc/ChangeLog: PR c/81405 * diagnostic-show-locus.c (fixit_cmp): New function. (layout::layout): Sort m_fixit_hints. (column_range::column_range): Assert that the values are valid. (struct char_span): New struct. (correction::overwrite): New method. (struct source_line): New struct. (line_corrections::add_hint): Add assertions. Reimplement memcpy calls in terms of classes source_line and char_span, and correction::overwrite. (selftest::test_overlapped_fixit_printing_2): New function. (selftest::diagnostic_show_locus_c_tests): Call it. gcc/testsuite/ChangeLog: PR c/81405 * gcc.dg/Wmissing-braces-fixits.c: Add coverage for PR c/81405. */ From-SVN: r250187
Diffstat (limited to 'gcc/gcc.c')
0 files changed, 0 insertions, 0 deletions