aboutsummaryrefslogtreecommitdiff
path: root/gcc/cppfiles.c
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.demon.co.uk>2001-11-26 23:44:54 +0000
committerNeil Booth <neil@gcc.gnu.org>2001-11-26 23:44:54 +0000
commit4d6baafa31576db4b1f5bc2d79913c9ce96e3a61 (patch)
treec1a2c9c7c2d1ce0412550e13966b5458cdbb8bbe /gcc/cppfiles.c
parentd4b4b319a23400caa59bbf0e2db01a8f0e38b34e (diff)
downloadgcc-4d6baafa31576db4b1f5bc2d79913c9ce96e3a61.zip
gcc-4d6baafa31576db4b1f5bc2d79913c9ce96e3a61.tar.gz
gcc-4d6baafa31576db4b1f5bc2d79913c9ce96e3a61.tar.bz2
cppfiles.c (stack_include_file): Don't optimize zero-length files.
* cppfiles.c (stack_include_file): Don't optimize zero-length files. (read_include_file): NUL-terminate read files. * cpplex.c (handle_newline, skip_escaped_newlines, get_effective_char, skip_whitespace, parse_identifier, parse_identifier_slow, parse_number, parse_string, _cpp_lex_direct): Optimize for the fact that buffers are guaranteed NUL-terminated. * cpplib.c (destringize_and_run, cpp_define, handle_assertion): Be sure buffers are NUL terminated. * cppmacro.c (warn_of_redefinition): Kill compile warning. * c-common.c: Include tree-inline.h. (c_language): Move separate definitions here. (c_common_init_options, c_common_post_options): New. (c_common_lang_init): Rename c_common_init. * c-common.h (c_common_lang_init): Similarly. (c_common_init_options, c_common_post_options): New. * c-lang.c (c_post_options): Move body to c_common_post_options. (c_init_options): Use c_common_init_options. (c_init): Update. * langhooks.def: Rearrange. * langhooks.h: Rearrange, and improve comments. * toplev.c (do_compile): New function. (toplev_main): Use it. (lang_independent_f_options, parse_options_and_default_flags, process_options): Remove trailing periods. * Makefile.in: Update. cp: * decl2.c (c_language): Move to c-common.c. * lex.c (cxx_post_options, cxx_init_options): Use c-common.c functions. (cxx_init): Update. objc: * objc-act.c (objc_post_options, objc_init_options): Use c-common.c functions. (ojbc_init): Update. From-SVN: r47362
Diffstat (limited to 'gcc/cppfiles.c')
-rw-r--r--gcc/cppfiles.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index 1fb357d..f0d85d9 100644
--- a/gcc/cppfiles.c
+++ b/gcc/cppfiles.c
@@ -296,17 +296,17 @@ stack_include_file (pfile, inc)
/* Not in cache? */
if (! inc->buffer)
{
- /* Mark a regular, zero-length file never-reread. Zero-length
- files are stacked the first time, so preprocessing a main
- file of zero length does not raise an error. */
- if (S_ISREG (inc->st.st_mode) && inc->st.st_size == 0)
- _cpp_never_reread (inc);
- else if (read_include_file (pfile, inc))
+ if (read_include_file (pfile, inc))
{
/* If an error occurs, do not try to read this file again. */
_cpp_never_reread (inc);
return false;
}
+ /* Mark a regular, zero-length file never-reread. We read it,
+ NUL-terminate it, and stack it once, so preprocessing a main
+ file of zero length does not raise an error. */
+ if (S_ISREG (inc->st.st_mode) && inc->st.st_size == 0)
+ _cpp_never_reread (inc);
close (inc->fd);
inc->fd = -1;
}
@@ -382,7 +382,8 @@ read_include_file (pfile, inc)
if (pagesize == -1)
pagesize = getpagesize ();
- if (size / pagesize >= MMAP_THRESHOLD)
+ if (size / pagesize >= MMAP_THRESHOLD
+ && (size % pagesize) != 0)
{
buf = (U_CHAR *) mmap (0, size, PROT_READ, MAP_PRIVATE, inc->fd, 0);
if (buf == (U_CHAR *)-1)
@@ -392,7 +393,7 @@ read_include_file (pfile, inc)
else
#endif
{
- buf = (U_CHAR *) xmalloc (size);
+ buf = (U_CHAR *) xmalloc (size + 1);
offset = 0;
while (offset < size)
{
@@ -410,6 +411,8 @@ read_include_file (pfile, inc)
}
offset += count;
}
+ /* The lexer requires that the buffer be NUL-terminated. */
+ buf[size] = '\0';
}
}
else if (S_ISBLK (inc->st.st_mode))
@@ -424,19 +427,25 @@ read_include_file (pfile, inc)
bigger than the majority of C source files. */
size = 8 * 1024;
- buf = (U_CHAR *) xmalloc (size);
+ buf = (U_CHAR *) xmalloc (size + 1);
offset = 0;
while ((count = read (inc->fd, buf + offset, size - offset)) > 0)
{
offset += count;
if (offset == size)
- buf = xrealloc (buf, (size *= 2));
+ {
+ size *= 2;
+ buf = xrealloc (buf, size + 1);
+ }
}
if (count < 0)
goto perror_fail;
- if (offset < size)
- buf = xrealloc (buf, offset);
+ if (offset + 1 < size)
+ buf = xrealloc (buf, offset + 1);
+
+ /* The lexer requires that the buffer be NUL-terminated. */
+ buf[offset] = '\0';
inc->st.st_size = offset;
}