aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authoredlinger <edlinger@138bc75d-0d04-0410-961f-82ee72b054a4>2014-09-30 16:08:53 +0000
committeredlinger <edlinger@138bc75d-0d04-0410-961f-82ee72b054a4>2014-09-30 16:08:53 +0000
commit2cb897aac5c37417a0d9df7bf097a0d0d97eef79 (patch)
treeab32b139b652fc4cee08f6e47ca2d986547e773f /libcpp
parenta226bafb7f8eee2bd325ef9f94074cdbb53cbff0 (diff)
2014-09-30 Bernd Edlinger <bernd.edlinger@hotmail.de>
PR preprocessor/58893 * errors.c (cpp_diagnostic): Fix possible out of bounds access. * files.c (_cpp_stack_include): Initialize src_loc for IT_CMDLINE. testsuite: 2014-09-30 Bernd Edlinger <bernd.edlinger@hotmail.de> PR preprocessor/58893 * gcc.dg/pr58893.c: New test case. * gcc.dg/pr58893-0.h: New include. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@215730 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog6
-rw-r--r--libcpp/errors.c5
-rw-r--r--libcpp/files.c12
3 files changed, 19 insertions, 4 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 463bb60e761..92999040a02 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,9 @@
+2014-09-30 Bernd Edlinger <bernd.edlinger@hotmail.de>
+
+ PR preprocessor/58893
+ * errors.c (cpp_diagnostic): Fix possible out of bounds access.
+ * files.c (_cpp_stack_include): Initialize src_loc for IT_CMDLINE.
+
2014-09-24 Marek Polacek <polacek@redhat.com>
PR c/61405
diff --git a/libcpp/errors.c b/libcpp/errors.c
index d1ca7a12ff4..bc857f0b81d 100644
--- a/libcpp/errors.c
+++ b/libcpp/errors.c
@@ -48,10 +48,7 @@ cpp_diagnostic (cpp_reader * pfile, int level, int reason,
current run -- that is invalid. */
else if (pfile->cur_token == pfile->cur_run->base)
{
- if (pfile->cur_run->prev != NULL)
- src_loc = pfile->cur_run->prev->limit->src_loc;
- else
- src_loc = 0;
+ src_loc = 0;
}
else
{
diff --git a/libcpp/files.c b/libcpp/files.c
index a442783f1d1..00302fd774f 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -991,6 +991,18 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
_cpp_file *file;
bool stacked;
+ /* For -include command-line flags we have type == IT_CMDLINE.
+ When the first -include file is processed we have the case, where
+ pfile->cur_token == pfile->cur_run->base, we are directly called up
+ by the front end. However in the case of the second -include file,
+ we are called from _cpp_lex_token -> _cpp_get_fresh_line ->
+ cpp_push_include, with pfile->cur_token != pfile->cur_run->base,
+ and pfile->cur_token[-1].src_loc not (yet) initialized.
+ However, when the include file cannot be found, we need src_loc to
+ be initialized to some safe value: 0 means UNKNOWN_LOCATION. */
+ if (type == IT_CMDLINE && pfile->cur_token != pfile->cur_run->base)
+ pfile->cur_token[-1].src_loc = 0;
+
dir = search_path_head (pfile, fname, angle_brackets, type);
if (!dir)
return false;