Commit 7868b4a2 by Neil Booth

cppfiles.c (_cpp_execute_include): Don't make a null-terminated copy of the filename.

	* cppfiles.c (_cpp_execute_include): Don't make a null-terminated
	copy of the filename.  Don't use CPP_PREV_BUFFER.  Don't call
	strlen or strcpy; we already know the length.
	(_cpp_compare_file_date): Similarly.
	* cpphash.h (struct cpp_reader): Delete done_initialising.
	(CPP_PREV_BUFFER): Delete.
	* cppinit.c (cpp_start_read): Don't set done_initialising.
	* cpplex.c (parse_string): Guarantee null-termination.
	(_cpp_equiv_toklists): Remove.
	* cpplib.c (glue_header_name): Null-terminate.
	(do_line): Don't leak memory.
	* cpplib.h (BT_WEAK): Delete.
	* cppmain.c (cb_ident): Strings are now null-terminated.

From-SVN: r40233
parent 91c704c4
2001-03-04 Laurynas Biveinis <lauras@softhome.net> 2001-03-04 Neil Booth <neil@daikokuya.demon.co.uk>
* gcc.c (convert_filename): Append executable suffix * cppfiles.c (_cpp_execute_include): Don't make a null-terminated
if NO_AUTO_EXE_SUFFIX is not defined. copy of the filename. Don't use CPP_PREV_BUFFER. Don't call
* gcc.texi: Document NO_AUTO_EXE_SUFFIX. strlen or strcpy; we already know the length.
* config/i386/djgpp.h: Define NO_AUTO_EXE_SUFFIX. (_cpp_compare_file_date): Similarly.
* cpphash.h (struct cpp_reader): Delete done_initialising.
(CPP_PREV_BUFFER): Delete.
* cppinit.c (cpp_start_read): Don't set done_initialising.
* cpplex.c (parse_string): Guarantee null-termination.
(_cpp_equiv_toklists): Remove.
* cpplib.c (glue_header_name): Null-terminate.
(do_line): Don't leak memory.
* cpplib.h (BT_WEAK): Delete.
* cppmain.c (cb_ident): Strings are now null-terminated.
2001-03-04 Laurynas Biveinis <lauras@softhome.net>
* gcc.c (convert_filename): Append executable suffix
if NO_AUTO_EXE_SUFFIX is not defined.
* gcc.texi: Document NO_AUTO_EXE_SUFFIX.
* config/i386/djgpp.h: Define NO_AUTO_EXE_SUFFIX.
2001-03-03 David O'Brien <obrien@FreeBSD.org> 2001-03-03 David O'Brien <obrien@FreeBSD.org>
......
...@@ -585,10 +585,9 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next) ...@@ -585,10 +585,9 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next)
int include_next; int include_next;
{ {
struct search_path *search_start = 0; struct search_path *search_start = 0;
unsigned int len = header->val.str.len;
unsigned int angle_brackets = header->type == CPP_HEADER_NAME; unsigned int angle_brackets = header->type == CPP_HEADER_NAME;
const char *fname = (const char *) header->val.str.text;
struct include_file *inc; struct include_file *inc;
char *fname;
int print_dep; int print_dep;
/* Help protect #include or similar from recursion. */ /* Help protect #include or similar from recursion. */
...@@ -626,10 +625,6 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next) ...@@ -626,10 +625,6 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next)
} }
} }
fname = alloca (len + 1);
memcpy (fname, header->val.str.text, len);
fname[len] = '\0';
if (!search_start) if (!search_start)
{ {
if (angle_brackets) if (angle_brackets)
...@@ -660,8 +655,8 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next) ...@@ -660,8 +655,8 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next)
/* Handle -H option. */ /* Handle -H option. */
if (CPP_OPTION (pfile, print_include_names)) if (CPP_OPTION (pfile, print_include_names))
{ {
cpp_buffer *fp = CPP_BUFFER (pfile); cpp_buffer *fp = pfile->buffer;
while ((fp = CPP_PREV_BUFFER (fp)) != NULL) while ((fp = fp->prev) != NULL)
putc ('.', stderr); putc ('.', stderr);
fprintf (stderr, " %s\n", inc->name); fprintf (stderr, " %s\n", inc->name);
} }
...@@ -692,13 +687,13 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next) ...@@ -692,13 +687,13 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next)
/* FIXME: ptr can be null, no? */ /* FIXME: ptr can be null, no? */
len = ptr->len; len = ptr->len;
p = (char *) alloca (len + strlen (fname) + 2); p = (char *) alloca (len + header->val.str.len + 2);
if (len) if (len)
{ {
memcpy (p, ptr->name, len); memcpy (p, ptr->name, len);
p[len++] = '/'; p[len++] = '/';
} }
strcpy (p + len, fname); memcpy (p + len, fname, header->val.str.len + 1);
_cpp_simplify_pathname (p); _cpp_simplify_pathname (p);
deps_add_dep (pfile->deps, p); deps_add_dep (pfile->deps, p);
} }
...@@ -722,8 +717,7 @@ _cpp_compare_file_date (pfile, f) ...@@ -722,8 +717,7 @@ _cpp_compare_file_date (pfile, f)
cpp_reader *pfile; cpp_reader *pfile;
const cpp_token *f; const cpp_token *f;
{ {
unsigned int len = f->val.str.len; const char *fname = (const char *) f->val.str.text;
char *fname;
struct search_path *search_start; struct search_path *search_start;
struct include_file *inc; struct include_file *inc;
...@@ -732,9 +726,6 @@ _cpp_compare_file_date (pfile, f) ...@@ -732,9 +726,6 @@ _cpp_compare_file_date (pfile, f)
else if (CPP_OPTION (pfile, ignore_srcdir)) else if (CPP_OPTION (pfile, ignore_srcdir))
search_start = pfile->buffer->search_from; search_start = pfile->buffer->search_from;
fname = alloca (len + 1);
memcpy (fname, f->val.str.text, len);
fname[len] = '\0';
inc = find_include_file (pfile, fname, search_start); inc = find_include_file (pfile, fname, search_start);
if (!inc) if (!inc)
......
...@@ -339,10 +339,6 @@ struct cpp_reader ...@@ -339,10 +339,6 @@ struct cpp_reader
/* We're printed a warning recommending against using #import. */ /* We're printed a warning recommending against using #import. */
unsigned char import_warning; unsigned char import_warning;
/* True after cpp_start_read completes. Used to inhibit some
warnings while parsing the command line. */
unsigned char done_initializing;
/* True if we are skipping a failed conditional group. */ /* True if we are skipping a failed conditional group. */
unsigned char skipping; unsigned char skipping;
...@@ -380,7 +376,6 @@ extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1]; ...@@ -380,7 +376,6 @@ extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
/* Macros. */ /* Macros. */
#define CPP_PREV_BUFFER(BUFFER) ((BUFFER)->prev)
#define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps) #define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
#define CPP_IN_SYSTEM_HEADER(PFILE) \ #define CPP_IN_SYSTEM_HEADER(PFILE) \
(CPP_BUFFER (PFILE) && CPP_BUFFER (PFILE)->sysp) (CPP_BUFFER (PFILE) && CPP_BUFFER (PFILE)->sysp)
......
...@@ -948,8 +948,6 @@ cpp_start_read (pfile, fname) ...@@ -948,8 +948,6 @@ cpp_start_read (pfile, fname)
p = q; p = q;
} }
pfile->done_initializing = 1;
/* The -imacros files can be scanned now, but the -include files /* The -imacros files can be scanned now, but the -include files
have to be pushed onto the buffer stack and processed later, have to be pushed onto the buffer stack and processed later,
otherwise cppmain.c won't see the tokens. include_head was built otherwise cppmain.c won't see the tokens. include_head was built
......
...@@ -629,10 +629,11 @@ unescaped_terminator_p (pfile, dest) ...@@ -629,10 +629,11 @@ unescaped_terminator_p (pfile, dest)
} }
/* Parses a string, character constant, or angle-bracketed header file /* Parses a string, character constant, or angle-bracketed header file
name. Handles embedded trigraphs and escaped newlines. name. Handles embedded trigraphs and escaped newlines. The stored
string is guaranteed NUL-terminated, but it is not guaranteed that
this is the first NUL since embedded NULs are preserved.
Multi-line strings are allowed, but they are deprecated within Multi-line strings are allowed, but they are deprecated. */
directives. */
static void static void
parse_string (pfile, token, terminator) parse_string (pfile, token, terminator)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -651,14 +652,21 @@ parse_string (pfile, token, terminator) ...@@ -651,14 +652,21 @@ parse_string (pfile, token, terminator)
for (;;) for (;;)
{ {
if (buffer->cur == buffer->rlimit) if (buffer->cur == buffer->rlimit)
c = EOF;
else
c = *buffer->cur++;
have_char:
/* We need space for the terminating NUL. */
if (dest >= limit)
limit = _cpp_next_chunk (pool, 0, &dest);
if (c == EOF)
{ {
c = EOF;
unterminated (pfile, terminator); unterminated (pfile, terminator);
break; break;
} }
c = *buffer->cur++;
have_char:
/* Handle trigraphs, escaped newlines etc. */ /* Handle trigraphs, escaped newlines etc. */
if (c == '?' || c == '\\') if (c == '?' || c == '\\')
c = skip_escaped_newlines (buffer, c); c = skip_escaped_newlines (buffer, c);
...@@ -690,8 +698,9 @@ parse_string (pfile, token, terminator) ...@@ -690,8 +698,9 @@ parse_string (pfile, token, terminator)
if (pfile->mlstring_pos.line == 0) if (pfile->mlstring_pos.line == 0)
pfile->mlstring_pos = pfile->lexer_pos; pfile->mlstring_pos = pfile->lexer_pos;
handle_newline (buffer, c); /* Stores to read_ahead. */ c = handle_newline (buffer, c);
c = '\n'; *dest++ = '\n';
goto have_char;
} }
else if (c == '\0') else if (c == '\0')
{ {
...@@ -699,25 +708,16 @@ parse_string (pfile, token, terminator) ...@@ -699,25 +708,16 @@ parse_string (pfile, token, terminator)
cpp_warning (pfile, "null character(s) preserved in literal"); cpp_warning (pfile, "null character(s) preserved in literal");
} }
/* No terminating null for strings - they could contain nulls. */
if (dest >= limit)
limit = _cpp_next_chunk (pool, 0, &dest);
*dest++ = c; *dest++ = c;
/* If we had a new line, the next character is in read_ahead. */
if (c != '\n')
continue;
c = buffer->read_ahead;
if (c != EOF)
goto have_char;
} }
/* Remember the next character. */ /* Remember the next character. */
buffer->read_ahead = c; buffer->read_ahead = c;
*dest = '\0';
token->val.str.text = POOL_FRONT (pool); token->val.str.text = POOL_FRONT (pool);
token->val.str.len = dest - token->val.str.text; token->val.str.len = dest - token->val.str.text;
POOL_COMMIT (pool, token->val.str.len); POOL_COMMIT (pool, token->val.str.len + 1);
} }
/* The stored comment includes the comment start and any terminator. */ /* The stored comment includes the comment start and any terminator. */
...@@ -1481,26 +1481,6 @@ _cpp_equiv_tokens (a, b) ...@@ -1481,26 +1481,6 @@ _cpp_equiv_tokens (a, b)
return 0; return 0;
} }
#if 0
/* Compare two token lists. */
int
_cpp_equiv_toklists (a, b)
const struct toklist *a, *b;
{
unsigned int i, count;
count = a->limit - a->first;
if (count != (b->limit - b->first))
return 0;
for (i = 0; i < count; i++)
if (! _cpp_equiv_tokens (&a->first[i], &b->first[i]))
return 0;
return 1;
}
#endif
/* Determine whether two tokens can be pasted together, and if so, /* Determine whether two tokens can be pasted together, and if so,
what the resulting token is. Returns CPP_EOF if the tokens cannot what the resulting token is. Returns CPP_EOF if the tokens cannot
be pasted, or the appropriate type for the merged token if they be pasted, or the appropriate type for the merged token if they
......
...@@ -525,8 +525,9 @@ glue_header_name (pfile, header) ...@@ -525,8 +525,9 @@ glue_header_name (pfile, header)
cpp_error (pfile, "missing terminating > character"); cpp_error (pfile, "missing terminating > character");
else else
{ {
token_mem = _cpp_pool_alloc (&pfile->ident_pool, total_len); token_mem = _cpp_pool_alloc (&pfile->ident_pool, total_len + 1);
memcpy (token_mem, buffer, total_len); memcpy (token_mem, buffer, total_len);
token_mem[total_len] = '\0';
header->type = CPP_HEADER_NAME; header->type = CPP_HEADER_NAME;
header->flags &= ~PREV_WHITE; header->flags &= ~PREV_WHITE;
...@@ -708,14 +709,10 @@ do_line (pfile) ...@@ -708,14 +709,10 @@ do_line (pfile)
if (token.type == CPP_STRING) if (token.type == CPP_STRING)
{ {
char *fname; char *fname;
unsigned int len; unsigned int len = token.val.str.len + 1;
/* FIXME: memory leak. */ fname = (char *) _cpp_pool_alloc (&pfile->ident_pool, len);
len = token.val.str.len;
fname = xmalloc (len + 1);
memcpy (fname, token.val.str.text, len); memcpy (fname, token.val.str.text, len);
fname[len] = '\0';
_cpp_simplify_pathname (fname); _cpp_simplify_pathname (fname);
/* Only accept flags for the # 55 form. */ /* Only accept flags for the # 55 form. */
......
...@@ -463,9 +463,7 @@ enum builtin_type ...@@ -463,9 +463,7 @@ enum builtin_type
BT_BASE_FILE, /* `__BASE_FILE__' */ BT_BASE_FILE, /* `__BASE_FILE__' */
BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */ BT_INCLUDE_LEVEL, /* `__INCLUDE_LEVEL__' */
BT_TIME, /* `__TIME__' */ BT_TIME, /* `__TIME__' */
BT_STDC, /* `__STDC__' */ BT_STDC /* `__STDC__' */
BT_WEAK /* Whether or not G++ supports weak
symbols. */
}; };
/* There is a slot in the hashnode for use by front ends when integrated /* There is a slot in the hashnode for use by front ends when integrated
......
...@@ -347,7 +347,7 @@ cb_ident (pfile, str) ...@@ -347,7 +347,7 @@ cb_ident (pfile, str)
const cpp_string * str; const cpp_string * str;
{ {
maybe_print_line (cpp_get_line (pfile)->output_line); maybe_print_line (cpp_get_line (pfile)->output_line);
fprintf (print.outf, "#ident \"%.*s\"\n", (int) str->len, str->text); fprintf (print.outf, "#ident \"%s\"\n", str->text);
print.lineno++; print.lineno++;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment