From 0e091b520e74abfcc98cd8b55525fce0ee50b6b6 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Mon, 13 Mar 2000 17:25:36 +0000 Subject: [PATCH] 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 From-SVN: r32507 --- gcc/ChangeLog | 6 ++++++ gcc/cpplib.c | 5 +++-- gcc/testsuite/gcc.dg/pr-impl.c | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr-impl.c 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 + + * 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 + 2000-03-13 Jason Merrill * 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 +#include +#pragma implementation "stdio.h" /* { dg-warning "appears after" "stdio.h" } */ -- 2.30.2