commit 5307c068b49ad94eeaf77b7fa1255ff49fa0a529
parent 47c4f8aebf11f33fa841c25d85ab33410668ea24
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 19 Jan 2016 14:25:43 +0100
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";
Diffstat:
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/cc1/code.c b/cc1/code.c
@@ -204,8 +204,9 @@ emitconst(Node *np)
/* 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;
diff --git a/cc1/init.c b/cc1/init.c
@@ -110,7 +110,9 @@ initialize(Type *tp)
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;
diff --git a/cc1/lex.c b/cc1/lex.c
@@ -483,7 +483,7 @@ repeat:
*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;