@@ -1709,6 +1709,8 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_c
harset,
to.text = input;
to.asize = size;
to.len = len;
+ if (CLEAR_CPP_PAD_BUFFER)
+ memset (input + size, 0, CPP_PAD_BUFFER_SIZE);
}
else
{
@@ -1731,7 +1733,12 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_
charset,
/* Resize buffer if we allocated substantially too much, or if we
haven't enough space for the \n-terminator. */
if (to.len + 4096 < to.asize || to.len >= to.asize)
- to.text = XRESIZEVEC (uchar, to.text, to.len + 1);
+ {
+ to.text = XRESIZEVEC (uchar, to.text,
+ to.len + CPP_PAD_BUFFER_SIZE + 1);
+ if (CLEAR_CPP_PAD_BUFFER)
+ memset (to.text + to.len + 1, 0, CPP_PAD_BUFFER_SIZE);
+ }
/* If the file is using old-school Mac line endings (\r only),
terminate with another \r, not an \n, so that we do not mistake
@@ -671,7 +671,7 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
the majority of C source files. */
size = 8 * 1024;
- buf = XNEWVEC (uchar, size + 1);
+ buf = XNEWVEC (uchar, size + CPP_PAD_BUFFER_SIZE + 1);
total = 0;
while ((count = read (file->fd, buf + total, size - total)) > 0)
{
@@ -682,7 +682,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 + CPP_PAD_BUFFER_SIZE + 1);
}
}
@@ -77,6 +77,16 @@ struct cset_converter
efficiency, and partly to limit runaway recursion. */
#define CPP_STACK_MAX 200
+/* Allocate extra 16 bytes for -fsanitize=address. */
+#ifdef __SANITIZE_ADDRESS__
+#define CPP_PAD_BUFFER_SIZE 16
+#else
+#define CPP_PAD_BUFFER_SIZE 0
+#endif
+
+/* 1 to clear extra 16 bytes. */
+#define CLEAR_CPP_PAD_BUFFER 0
+
/* Host alignment handling. */
struct dummy
{