summaryrefslogtreecommitdiff
path: root/libcpp/files.c
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2008-04-21 14:02:00 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2008-04-21 14:02:00 +0000
commitd656d07a0ea99c1a5c9c8273f2fe486381e12c15 (patch)
tree95c70d6534e91125519d9a8f2e7c2cf84de0c82b /libcpp/files.c
parent7f0c1cb278a40dd00f83f7253eedf3d227c3937f (diff)
downloadgcc-d656d07a0ea99c1a5c9c8273f2fe486381e12c15.tar.gz
libcpp
PR libcpp/33415: * charset.c (_cpp_convert_input): Add buffer_start argument. Ignore UTF-8 BOM if seen. * internal.h (_cpp_convert_input): Add argument. * files.c (struct _cpp_file) <buffer_start>: New field. (destroy_cpp_file): Free buffer_start, not buffer. (_cpp_pop_file_buffer): Likewise. (read_file_guts): Update. gcc/testsuite PR libcpp/33415: * gcc.dg/cpp/pr33415.c: New file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@134507 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp/files.c')
-rw-r--r--libcpp/files.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/libcpp/files.c b/libcpp/files.c
index 2bc3a801e35..1adc58d88a8 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -74,6 +74,10 @@ struct _cpp_file
/* The contents of NAME after calling read_file(). */
const uchar *buffer;
+ /* Pointer to the real start of BUFFER. read_file() might increment
+ BUFFER; when freeing, this this pointer must be used instead. */
+ const uchar *buffer_start;
+
/* The macro, if any, preventing re-inclusion. */
const cpp_hashnode *cmacro;
@@ -635,8 +639,11 @@ read_file_guts (cpp_reader *pfile, _cpp_file *file)
cpp_error (pfile, CPP_DL_WARNING,
"%s is shorter than expected", file->path);
- file->buffer = _cpp_convert_input (pfile, CPP_OPTION (pfile, input_charset),
- buf, size, total, &file->st.st_size);
+ file->buffer = _cpp_convert_input (pfile,
+ CPP_OPTION (pfile, input_charset),
+ buf, size, total,
+ &file->buffer_start,
+ &file->st.st_size);
file->buffer_valid = true;
return true;
@@ -969,8 +976,8 @@ make_cpp_file (cpp_reader *pfile, cpp_dir *dir, const char *fname)
static void
destroy_cpp_file (_cpp_file *file)
{
- if (file->buffer)
- free ((void *) file->buffer);
+ if (file->buffer_start)
+ free ((void *) file->buffer_start);
free ((void *) file->name);
free (file);
}
@@ -1302,9 +1309,10 @@ _cpp_pop_file_buffer (cpp_reader *pfile, _cpp_file *file)
/* Invalidate control macros in the #including file. */
pfile->mi_valid = false;
- if (file->buffer)
+ if (file->buffer_start)
{
- free ((void *) file->buffer);
+ free ((void *) file->buffer_start);
+ file->buffer_start = NULL;
file->buffer = NULL;
file->buffer_valid = false;
}