summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-03-13 17:25:36 +0000
committerzack <zack@138bc75d-0d04-0410-961f-82ee72b054a4>2000-03-13 17:25:36 +0000
commit3c875b488ea3a1b094a706f3bee85fd145c78e08 (patch)
treebecf3668ee98ea8419e3774e66c8b82085465239
parent4e1d939e37597f768350e774bca21208e24fedee (diff)
downloadppe42-gcc-3c875b488ea3a1b094a706f3bee85fd145c78e08.tar.gz
ppe42-gcc-3c875b488ea3a1b094a706f3bee85fd145c78e08.zip
* cpplib.c (do_pragma_implementation): Fix off-by-one error
truncating a string. Don't assume tokens are nul terminated. Problem noted by Andreas Jaeger <aj@suse.de> git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@32507 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/cpplib.c5
-rw-r--r--gcc/testsuite/gcc.dg/pr-impl.c7
3 files changed, 16 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b9394c558d7..0d8d1d3bb52 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2000-03-13 Zack Weinberg <zack@wolery.cumb.org>
+
+ * cpplib.c (do_pragma_implementation): Fix off-by-one error
+ truncating a string. Don't assume tokens are nul terminated.
+ Problem noted by Andreas Jaeger <aj@suse.de>
+
2000-03-13 Jason Merrill <jason@casey.cygnus.com>
* dwarf2out.c (add_name_and_src_coords_attributes): Only add
diff --git a/gcc/cpplib.c b/gcc/cpplib.c
index 91f86b7cb4a..02a93185fce 100644
--- a/gcc/cpplib.c
+++ b/gcc/cpplib.c
@@ -1705,11 +1705,12 @@ do_pragma_implementation (pfile)
return 1;
}
+ /* Trim the leading and trailing quote marks from the string. */
name = pfile->token_buffer + written + 1;
- len = strlen (name);
+ len = CPP_PWRITTEN (pfile) - name;
copy = (U_CHAR *) alloca (len);
memcpy (copy, name, len - 1);
- copy[len] = '\0'; /* trim trailing quote */
+ copy[len - 1] = '\0';
if (cpp_included (pfile, copy))
cpp_warning (pfile,
diff --git a/gcc/testsuite/gcc.dg/pr-impl.c b/gcc/testsuite/gcc.dg/pr-impl.c
new file mode 100644
index 00000000000..60836798d0c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr-impl.c
@@ -0,0 +1,7 @@
+/* Test warnings generated by #pragma implementation in the wrong place. */
+/* { dg-do preprocess } */
+
+#pragma implementation "stdlib.h" /* { dg-bogus "appears after" "stdlib.h" } */
+#include <stdlib.h>
+#include <stdio.h>
+#pragma implementation "stdio.h" /* { dg-warning "appears after" "stdio.h" } */
OpenPOWER on IntegriCloud