aboutsummaryrefslogtreecommitdiff
path: root/libcpp/files.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2012-12-03 18:19:47 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2012-12-03 18:19:47 +0100
commitf41e5bd19ddc48d291b01a270623c379568d325d (patch)
tree0631b731076c534491f883f189109e95a9bd12d4 /libcpp/files.c
parent36402bb1864531f22acc9c3ef2403e1d3cddfc65 (diff)
downloadgcc-f41e5bd19ddc48d291b01a270623c379568d325d.zip
gcc-f41e5bd19ddc48d291b01a270623c379568d325d.tar.gz
gcc-f41e5bd19ddc48d291b01a270623c379568d325d.tar.bz2
re PR bootstrap/55380 (All search_line_fast implementations read beyond buffer)
PR bootstrap/55380 PR other/54691 * files.c (read_file_guts): Allocate extra 16 bytes instead of 1 byte at the end of buf. Pass size + 16 instead of size to _cpp_convert_input. * charset.c (_cpp_convert_input): Reallocate if there aren't at least 16 bytes beyond to.len in the buffer. Clear 16 bytes at to.text + to.len. From-SVN: r194102
Diffstat (limited to 'libcpp/files.c')
-rw-r--r--libcpp/files.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/libcpp/files.c b/libcpp/files.c
index 9f84d8c..3aeb6f3 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -671,7 +671,11 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
the majority of C source files. */
size = 8 * 1024;
- buf = XNEWVEC (uchar, size + 1);
+ /* The + 16 here is space for the final '\n' and 15 bytes of padding,
+ used to quiet warnings from valgrind or Address Sanitizer, when the
+ optimized lexer accesses aligned 16-byte memory chunks, including
+ the bytes after the malloced, area, and stops lexing on '\n'. */
+ buf = XNEWVEC (uchar, size + 16);
total = 0;
while ((count = read (file->fd, buf + total, size - total)) > 0)
{
@@ -682,7 +686,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
if (regular)
break;
size *= 2;
- buf = XRESIZEVEC (uchar, buf, size + 1);
+ buf = XRESIZEVEC (uchar, buf, size + 16);
}
}
@@ -699,7 +703,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
file->buffer = _cpp_convert_input (pfile,
CPP_OPTION (pfile, input_charset),
- buf, size, total,
+ buf, size + 16, total,
&file->buffer_start,
&file->st.st_size);
file->buffer_valid = true;