diff options
author | Zack Weinberg <zack@wolery.cumb.org> | 2000-03-13 17:25:36 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 2000-03-13 17:25:36 +0000 |
commit | 0e091b520e74abfcc98cd8b55525fce0ee50b6b6 (patch) | |
tree | becf3668ee98ea8419e3774e66c8b82085465239 /gcc | |
parent | bc808e0bc5cff1895e4d6c29a8ee7775cef10594 (diff) | |
download | gcc-0e091b520e74abfcc98cd8b55525fce0ee50b6b6.zip gcc-0e091b520e74abfcc98cd8b55525fce0ee50b6b6.tar.gz gcc-0e091b520e74abfcc98cd8b55525fce0ee50b6b6.tar.bz2 |
cpplib.c (do_pragma_implementation): Fix off-by-one error truncating a string.
* 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>
From-SVN: r32507
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cpplib.c | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr-impl.c | 7 |
3 files changed, 16 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b9394c5..0d8d1d3 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 91f86b7..02a9318 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 0000000..6083679 --- /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" } */ |