commit 41b20e066ab2f220c3a6b5107a546d17fbcc891f
parent 4eff786be3921ff7e1fc90b57e7f0a8932a1fda1
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 16 Jan 2017 16:17:08 +0100
[cc1] Ue tok2str() in character()
This function handles the buffer overrun.
Diffstat:
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/cc1/lex.c b/cc1/lex.c
@@ -278,7 +278,7 @@ tok2str(void)
 {
 	if ((yylen = input->p - input->begin) > INTIDENTSIZ)
 		error("token too big");
-	strncpy(yytext, input->begin, yylen);
+	memcpy(yytext, input->begin, yylen);
 	yytext[yylen] = '\0';
 	input->begin = input->p;
 }
@@ -467,11 +467,9 @@ escape(void)
 static unsigned
 character(void)
 {
-	char c, *p;
+	char c;
 	Symbol *sym;
-	size_t size;
 
-	p = input->p;
 	if ((c = *++input->p) == '\\')
 		c = escape();
 	else
@@ -482,14 +480,11 @@ character(void)
 	else
 		++input->p;
 
-	size = input->p - p;
-	memcpy(yytext, p, size);
-	yytext[size] = '\0';
-
 	sym = newsym(NS_IDEN, NULL);
 	sym->u.i = c;
 	sym->type = inttype;
 	yylval.sym = sym;
+	tok2str();
 	return CONSTANT;
 }