shithub: scc

Download patch

ref: 5307c068b49ad94eeaf77b7fa1255ff49fa0a529
parent: 47c4f8aebf11f33fa841c25d85ab33410668ea24
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Jan 19 09:25:43 EST 2016

Print all the bytes of strings

We have to print all the bytes of strings, because not all the strings
are going to have a EOS. For example:

char m[2] = "foo";

--- a/cc1/code.c
+++ b/cc1/code.c
@@ -204,8 +204,9 @@
 		/* TODO: All this code must go out */
 		if (sym->flags & ISSTRING) {
 			putchar('"');
-			for (bp = sym->u.s; c = *bp; ++bp)
-				printf("%02X", c & 0xFF);
+			n = tp->n.elem;
+			for (bp = sym->u.s; n-- > 0; ++bp)
+				printf("%02X", (*bp) & 0xFF);
 			/* TODO: Why we don't free here? */
 		} else if (sym->flags & ISINITLST) {
 			n = tp->n.elem;
--- a/cc1/init.c
+++ b/cc1/init.c
@@ -110,7 +110,9 @@
 			tp->n.elem = len;
 		} else if (tp->n.elem < len) {
 			warn("initializer-string for array of chars is too long");
-			np->sym = newstring(sym->u.s, tp->n.elem);
+			sym = newstring(sym->u.s, tp->n.elem);
+			np->sym = sym;
+			np->type = sym->type;
 		}
 
 		return np;
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -483,7 +483,7 @@
 	*bp = '\0';
 
 	yylen = bp - yytext + 1;
-	yylval.sym = newstring(yytext+1, yylen-2);
+	yylval.sym = newstring(yytext+1, yylen-1);
 	*bp++ = '"';
 	*bp = '\0';
 	return CONSTANT;