[hackers] [scc] Print all the bytes of strings || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 19 Jan 2016 15:40:04 +0100 (CET)

commit 5307c068b49ad94eeaf77b7fa1255ff49fa0a529
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Jan 19 14:25:43 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Jan 19 14:25:43 2016 +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";

diff --git a/cc1/code.c b/cc1/code.c
index ad88b32..0b694c7 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -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
index bf34759..6418da2 100644
--- a/cc1/init.c
+++ b/cc1/init.c
_AT_@ -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
index 8cf890c..0f64618 100644
--- a/cc1/lex.c
+++ b/cc1/lex.c
_AT_@ -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;
Received on Tue Jan 19 2016 - 15:40:04 CET

This archive was generated by hypermail 2.3.0 : Tue Jan 19 2016 - 15:48:30 CET