[hackers] [scc] Fix emitcons() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 21 Jul 2015 17:58:25 +0200 (CEST)

commit fee4eeac3d4259a138bf98212c72faf394fcd379
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Jul 21 17:53:47 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Jul 21 17:53:47 2015 +0200

    Fix emitcons()
    
    Before of this commit the function was assuming that all the integer
    constant were of type inttype, and the rest were strings, generating
    a segfault with a long variable for example. This patch adds a skeleton
    of what have to be done and a bit of checking.

diff --git a/cc1/TODO b/cc1/TODO
index 4ec9a31..8383cab 100644
--- a/cc1/TODO
+++ b/cc1/TODO
_AT_@ -16,3 +16,4 @@
 * Implement enum type in eqtype()
 * Parse correctly all integer and float constants
 * Add C99 features (almost all the new features of C99 are missed)
+* Add correct emit for any kind of constant
diff --git a/cc1/code.c b/cc1/code.c
index 937a625..d7aec72 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -177,12 +177,22 @@ emitconst(Node *np)
         char *bp, c;
         Symbol *sym = np->sym;
 
- if (np->type == inttype) {
+ switch (np->type->op) {
+ case INT:
                 printf("#%c%x", np->type->letter, sym->u.i);
- } else {
+ break;
+ case ARY:
+ /*
+ * FIX: At this point we are going to assume
+ * that all the arrays are strings
+ */
                 putchar('"');
                 for (bp = sym->u.s; c = *bp; ++bp)
- printf("%02X", (unsigned) c);
+ printf("%02X", c & 0xFF);
+ break;
+ default:
+ /* TODO: Handle other kind of constants */
+ abort;
         }
 }
 
Received on Tue Jul 21 2015 - 17:58:25 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 21 2015 - 18:00:14 CEST