Commit 2387c1d4 by Zack Weinberg Committed by Zack Weinberg

cpplib.c (cpp_define, cpp_undef): Make sure the stacked buffer ends with a newline and a NUL.

	* cpplib.c (cpp_define, cpp_undef): Make sure the stacked buffer
	ends with a newline and a NUL.  Don't be so clever manipulating
	strings.

From-SVN: r31864
parent e8b22dd1
2000-02-09 Zack Weinberg <zack@wolery.cumb.org>
* cpplib.c (cpp_define, cpp_undef): Make sure the stacked buffer
ends with a newline and a NUL. Don't be so clever manipulating
strings.
Wed Feb 9 14:18:08 MET 2000 Jan Hubicka <jh@suse.cz> Wed Feb 9 14:18:08 MET 2000 Jan Hubicka <jh@suse.cz>
* reload1.c (reload) Align stack frame to cfun->stack_alignment_needed, * reload1.c (reload) Align stack frame to cfun->stack_alignment_needed,
......
...@@ -191,6 +191,11 @@ cpp_grow_buffer (pfile, n) ...@@ -191,6 +191,11 @@ cpp_grow_buffer (pfile, n)
If STR has anything after the identifier, then it should If STR has anything after the identifier, then it should
be identifier=definition. */ be identifier=definition. */
/* Process the string STR as if it appeared as the body of a #define
If STR is just an identifier, define it with value 1.
If STR has anything after the identifier, then it should
be identifier=definition. */
void void
cpp_define (pfile, str) cpp_define (pfile, str)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -199,21 +204,28 @@ cpp_define (pfile, str) ...@@ -199,21 +204,28 @@ cpp_define (pfile, str)
U_CHAR *buf, *p; U_CHAR *buf, *p;
size_t count; size_t count;
/* Copy the entire option so we can modify it. */ p = strchr (str, '=');
count = strlen (str) + 3; /* Copy the entire option so we can modify it.
buf = (U_CHAR *) alloca (count); Change the first "=" in the string to a space. If there is none,
memcpy (buf, str, count - 2); tack " 1" on the end. Then add a newline and a NUL. */
/* Change the first "=" in the string to a space. If there is none,
tack " 1" on the end. */
p = (U_CHAR *) strchr (buf, '=');
if (p) if (p)
{ {
*p = ' '; count = strlen (str) + 2;
count -= 2; buf = (U_CHAR *) alloca (count);
memcpy (buf, str, count - 2);
buf[p - str] = ' ';
buf[count - 2] = '\n';
buf[count - 1] = '\0';
} }
else else
strcpy (&buf[count-3], " 1"); {
count = strlen (str) + 4;
buf = (U_CHAR *) alloca (count);
memcpy (buf, str, count - 4);
strcpy (&buf[count-4], " 1\n");
}
if (cpp_push_buffer (pfile, buf, count - 1) != NULL) if (cpp_push_buffer (pfile, buf, count - 1) != NULL)
{ {
do_define (pfile, NULL); do_define (pfile, NULL);
...@@ -1476,14 +1488,19 @@ cpp_undef (pfile, macro) ...@@ -1476,14 +1488,19 @@ cpp_undef (pfile, macro)
cpp_reader *pfile; cpp_reader *pfile;
U_CHAR *macro; U_CHAR *macro;
{ {
if (cpp_push_buffer (pfile, macro, strlen (macro))) /* Copy the string so we can append a newline. */
size_t len = strlen (macro);
U_CHAR *buf = alloca (len + 2);
memcpy (buf, macro, len);
buf[len] = '\n';
buf[len + 1] = '\0';
if (cpp_push_buffer (pfile, buf, len + 1))
{ {
do_undef (pfile, NULL); do_undef (pfile, NULL);
cpp_pop_buffer (pfile); cpp_pop_buffer (pfile);
} }
} }
/* /*
* Report an error detected by the program we are processing. * Report an error detected by the program we are processing.
* Use the text of the line in the error message. * Use the text of the line in the error message.
......
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