scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 94fd29519bd9650953b1f9b67ae62c628678297d
parent 7267f1845ababef928b82541085e574a20d29856
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 30 May 2012 20:08:42 +0200

Fixed bug calculating hash of identifiers

Instead of calculating hash as modulus, we were using the division.

Diffstat:
Mlex.c | 6+++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lex.c b/lex.c @@ -80,7 +80,7 @@ void init_lex(void) for (bp = keywords; bp->str; bp++) { register struct keyword *aux, *ant; - h = hashfun(bp->str) % (NR_KWD_HASH - 1); + h = hashfun(bp->str) & (NR_KWD_HASH - 1); if (!(aux = khash[h]) || strcmp(bp->str, aux->str) < 0) { khash[h] = bp; bp->next = aux; @@ -142,7 +142,7 @@ unsigned char gettok(void) ; } else { switch (ch) { - case '&': case '|': + case '&': case '|': if ((c = getc(yyin)) == ch) { yytext[1] = yytext[0] = ch; yytext[2] = '\0'; @@ -152,7 +152,7 @@ unsigned char gettok(void) ungetc(c, yyin); } case '^': case '=': case '<': case '>': - case '*': case '+': case '-': case '/': + case '*': case '+': case '-': case '/': if ((c = getc(yyin)) == '=') { yytext[0] = ch; yytext[1] = c;