PR c++/70693 reports a crash within -Wmisleading-indentation in get_visual_column, reading past the end of a source line. The issue occurs due to a stray carriage return aka '\r' aka ^M, occurring towards the end of line 35 of attachment 38289 - but not at the end itself. This carriage return confuses our line numbering: from that point in the file, the lexer (and thus location_t values) use line numbers that are one larger than those seen by input.c, "cat -n" and emacs. This discrepancy between the lexer's line numbering and input.c's line numbering leads to an out-of-range read in get_visual_column (trying to read column 8, to locate the first non-whitespace on the line containing "break;", but finding the next line, which is only 4 characters long). This patch fixes the ICE by adding a range check to get_visual_column before accessing the input.c line buffer. This is arguably papering over the root cause, but there are presumably other ways of triggering such an out-of-range read by writing to the source file after the lexer but before -Wmisleading-indentation, and we ought to be not ICE in the face of that. gcc/c-family/ChangeLog: PR c++/70693 * c-common.c (selftest::c_family_tests): Call selftest::c_indentation_c_tests. * c-common.h (selftest::c_indentation_c_tests): New decl. * c-indentation.c: Include "selftest.h". (next_tab_stop): Add "tab_width" param, rather than accessing cpp_opts. (get_visual_column): Likewise. Clarify comment. Bulletproof against reading past the end of the line. (get_first_nws_vis_column): Add "tab_width" param. (detect_intervening_unindent): Likewise. (should_warn_for_misleading_indentation): Read tab width from cpp_opts and pass around. (selftest::test_next_tab_stop): New test. (selftest::assert_get_visual_column_succeeds): New function. (ASSERT_GET_VISUAL_COLUMN_SUCCEEDS): New macro. (selftest::assert_get_visual_column_fails): New function. (ASSERT_GET_VISUAL_COLUMN_FAILS): New macro. (selftest::test_get_visual_column): New test. (selftest::c_indentation_c_tests): New function. gcc/testsuite/ChangeLog: PR c++/70693 * c-c++-common/Wmisleading-indentation-pr70693.c: New test. From-SVN: r263595
Name |
Last commit
|
Last update |
---|---|---|
INSTALL | Loading commit data... | |
config | Loading commit data... | |
contrib | Loading commit data... | |
fixincludes | Loading commit data... | |
gcc | Loading commit data... | |
gnattools | Loading commit data... | |
gotools | Loading commit data... | |
include | Loading commit data... | |
intl | Loading commit data... | |
libada | Loading commit data... | |
libatomic | Loading commit data... | |
libbacktrace | Loading commit data... | |
libcc1 | Loading commit data... | |
libcpp | Loading commit data... | |
libdecnumber | Loading commit data... | |
libffi | Loading commit data... | |
libgcc | Loading commit data... | |
libgfortran | Loading commit data... | |
libgo | Loading commit data... | |
libgomp | Loading commit data... | |
libhsail-rt | Loading commit data... | |
libiberty | Loading commit data... | |
libitm | Loading commit data... | |
libobjc | Loading commit data... | |
liboffloadmic | Loading commit data... | |
libquadmath | Loading commit data... | |
libsanitizer | Loading commit data... | |
libssp | Loading commit data... | |
libstdc++-v3 | Loading commit data... | |
libvtv | Loading commit data... | |
lto-plugin | Loading commit data... | |
maintainer-scripts | Loading commit data... | |
zlib | Loading commit data... | |
.dir-locals.el | Loading commit data... | |
.gitattributes | Loading commit data... | |
.gitignore | Loading commit data... | |
ABOUT-NLS | Loading commit data... | |
COPYING | Loading commit data... | |
COPYING.LIB | Loading commit data... | |
COPYING.RUNTIME | Loading commit data... | |
COPYING3 | Loading commit data... | |
COPYING3.LIB | Loading commit data... | |
ChangeLog | Loading commit data... | |
ChangeLog.jit | Loading commit data... | |
ChangeLog.tree-ssa | Loading commit data... | |
MAINTAINERS | Loading commit data... | |
Makefile.def | Loading commit data... | |
Makefile.in | Loading commit data... | |
Makefile.tpl | Loading commit data... | |
README | Loading commit data... | |
compile | Loading commit data... | |
config-ml.in | Loading commit data... | |
config.guess | Loading commit data... | |
config.rpath | Loading commit data... | |
config.sub | Loading commit data... | |
configure | Loading commit data... | |
configure.ac | Loading commit data... | |
depcomp | Loading commit data... | |
install-sh | Loading commit data... | |
libtool-ldflags | Loading commit data... | |
libtool.m4 | Loading commit data... | |
ltgcc.m4 | Loading commit data... | |
ltmain.sh | Loading commit data... | |
ltoptions.m4 | Loading commit data... | |
ltsugar.m4 | Loading commit data... | |
ltversion.m4 | Loading commit data... | |
lt~obsolete.m4 | Loading commit data... | |
missing | Loading commit data... | |
mkdep | Loading commit data... | |
mkinstalldirs | Loading commit data... | |
move-if-change | Loading commit data... | |
symlink-tree | Loading commit data... | |
ylwrap | Loading commit data... |