Commit 6ee2c979 by Zack Weinberg

cppalloc.c (xstrdup): Use memcpy.

1999-09-10 22:37 -0700  Zack Weinberg  <zack@bitmover.com>

	* cppalloc.c (xstrdup): Use memcpy.
	* cpperror.c (cpp_print_containing_files): Don't use
	cpp_notice.
	* cpplib.c (conditional_skip): Set temp->lineno.
	(do_endif): Make error message less obscure.
	(if_directive_name): New function.
	(cpp_get_token [case EOF]): Unwind the if stack and generate
	error messages for each unterminated conditional in this file.
	(parse_string):  Do not behave differently if -traditional.

From-SVN: r29279
parent 27e934d8
1999-09-10 22:37 -0700 Zack Weinberg <zack@bitmover.com>
* cppalloc.c (xstrdup): Use memcpy.
* cpperror.c (cpp_print_containing_files): Don't use
cpp_notice.
* cpplib.c (conditional_skip): Set temp->lineno.
(do_endif): Make error message less obscure.
(if_directive_name): New function.
(cpp_get_token [case EOF]): Unwind the if stack and generate
error messages for each unterminated conditional in this file.
(parse_string): Do not behave differently if -traditional.
Fri Sep 10 14:04:07 1999 Richard Henderson <rth@cygnus.com> Fri Sep 10 14:04:07 1999 Richard Henderson <rth@cygnus.com>
* builtins.c (expand_builtin_va_arg): Cope with an array-type * builtins.c (expand_builtin_va_arg): Cope with an array-type
......
...@@ -74,8 +74,8 @@ char * ...@@ -74,8 +74,8 @@ char *
xstrdup (input) xstrdup (input)
const char *input; const char *input;
{ {
unsigned size = strlen (input); size_t size = strlen (input) + 1;
char *output = xmalloc (size + 1); char *output = xmalloc (size);
strcpy (output, input); memcpy (output, input, size);
return output; return output;
} }
...@@ -63,7 +63,7 @@ cpp_print_containing_files (pfile) ...@@ -63,7 +63,7 @@ cpp_print_containing_files (pfile)
if (first) if (first)
{ {
first = 0; first = 0;
cpp_notice ("In file included from %s:%ld", cpp_message (pfile, -1, "In file included from %s:%ld",
ip->nominal_fname, line); ip->nominal_fname, line);
} }
else else
......
...@@ -1944,9 +1944,7 @@ conditional_skip (pfile, skip, type, control_macro) ...@@ -1944,9 +1944,7 @@ conditional_skip (pfile, skip, type, control_macro)
temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME)); temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
temp->fname = CPP_BUFFER (pfile)->nominal_fname; temp->fname = CPP_BUFFER (pfile)->nominal_fname;
#if 0
temp->lineno = CPP_BUFFER (pfile)->lineno; temp->lineno = CPP_BUFFER (pfile)->lineno;
#endif
temp->next = pfile->if_stack; temp->next = pfile->if_stack;
temp->control_macro = control_macro; temp->control_macro = control_macro;
pfile->if_stack = temp; pfile->if_stack = temp;
...@@ -2177,7 +2175,7 @@ do_endif (pfile, keyword) ...@@ -2177,7 +2175,7 @@ do_endif (pfile, keyword)
skip_rest_of_line (pfile); skip_rest_of_line (pfile);
if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
cpp_error (pfile, "unbalanced `#endif'"); cpp_error (pfile, "`#endif' not within a conditional");
else else
{ {
IF_STACK_FRAME *temp = pfile->if_stack; IF_STACK_FRAME *temp = pfile->if_stack;
...@@ -2235,6 +2233,25 @@ validate_else (pfile, directive) ...@@ -2235,6 +2233,25 @@ validate_else (pfile, directive)
"text following `%s' violates ANSI standard", directive); "text following `%s' violates ANSI standard", directive);
} }
/* Convert T_IF, etc. to a string. Used in error messages. */
static const char *
if_directive_name (pfile, ifs)
cpp_reader *pfile;
struct if_stack *ifs;
{
switch (ifs->type)
{
case T_IF: return "#if";
case T_IFDEF: return "#ifdef";
case T_IFNDEF: return "#ifndef";
case T_ELIF: return "#elif";
case T_ELSE: return "#else";
default:
cpp_fatal (pfile, "impossible if_stack->type value %d", ifs->type);
return "unknown";
}
}
/* Get the next token, and add it to the text in pfile->token_buffer. /* Get the next token, and add it to the text in pfile->token_buffer.
Return the kind of token we got. */ Return the kind of token we got. */
...@@ -2265,9 +2282,23 @@ cpp_get_token (pfile) ...@@ -2265,9 +2282,23 @@ cpp_get_token (pfile)
} }
else else
{ {
cpp_buffer *next_buf cpp_buffer *next_buf = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
= CPP_PREV_BUFFER (CPP_BUFFER (pfile)); struct if_stack *ifs, *nifs;
CPP_BUFFER (pfile)->seen_eof = 1;
/* Unwind the conditional stack and generate error messages. */
for (ifs = pfile->if_stack;
ifs != CPP_BUFFER (pfile)->if_stack;
ifs = nifs)
{
cpp_error_with_line (pfile, ifs->lineno, -1,
"unterminated `%s' conditional",
if_directive_name (pfile, ifs));
nifs = ifs->next;
free (ifs);
}
pfile->if_stack = ifs;
if (CPP_BUFFER (pfile)->nominal_fname if (CPP_BUFFER (pfile)->nominal_fname
&& next_buf != CPP_NULL_BUFFER (pfile)) && next_buf != CPP_NULL_BUFFER (pfile))
{ {
...@@ -2280,6 +2311,8 @@ cpp_get_token (pfile) ...@@ -2280,6 +2311,8 @@ cpp_get_token (pfile)
output_line_command (pfile, leave_file); output_line_command (pfile, leave_file);
CPP_BUFFER (pfile) = cur_buffer; CPP_BUFFER (pfile) = cur_buffer;
} }
CPP_BUFFER (pfile)->seen_eof = 1;
return CPP_POP; return CPP_POP;
} }
} }
...@@ -2824,8 +2857,7 @@ parse_string (pfile, c) ...@@ -2824,8 +2857,7 @@ parse_string (pfile, c)
cpp_pop_buffer (pfile); cpp_pop_buffer (pfile);
continue; continue;
} }
if (!CPP_TRADITIONAL (pfile))
{
cpp_error_with_line (pfile, start_line, start_column, cpp_error_with_line (pfile, start_line, start_column,
"unterminated string or character constant"); "unterminated string or character constant");
if (pfile->multiline_string_line != start_line if (pfile->multiline_string_line != start_line
...@@ -2834,7 +2866,6 @@ parse_string (pfile, c) ...@@ -2834,7 +2866,6 @@ parse_string (pfile, c)
pfile->multiline_string_line, -1, pfile->multiline_string_line, -1,
"possible real start of unterminated constant"); "possible real start of unterminated constant");
pfile->multiline_string_line = 0; pfile->multiline_string_line = 0;
}
break; break;
} }
CPP_PUTC (pfile, cc); CPP_PUTC (pfile, cc);
...@@ -2843,11 +2874,9 @@ parse_string (pfile, c) ...@@ -2843,11 +2874,9 @@ parse_string (pfile, c)
case '\n': case '\n':
CPP_BUMP_LINE (pfile); CPP_BUMP_LINE (pfile);
pfile->lineno++; pfile->lineno++;
/* Traditionally, end of line ends a string constant with /* Character constants may not extend over multiple lines.
no error. */ In ANSI, neither may strings. We accept multiline strings
if (CPP_TRADITIONAL (pfile)) as an extension. */
return;
/* Character constants may not extend over multiple lines. */
if (c == '\'') if (c == '\'')
{ {
cpp_error_with_line (pfile, start_line, start_column, cpp_error_with_line (pfile, start_line, start_column,
......
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