scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 7ae2f8e3d575dd2e918c3b389779415e63902d8b
parent fec677da96689271e3be450a07961b56267f0afc
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  9 Feb 2012 11:09:25 +0100

Fixed bug inserting in keyword hash

Code tested only that pointer of array hashing was null in order to insert
directly in the queue, but it was falling of testing if first element if bigger than new element, because in this case we were creating a corrupted circular
list

Diffstat:
lex.c | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lex.c b/lex.c @@ -78,14 +78,14 @@ void init_lex(void) for (bp = keywords; bp->str; bp++) { register struct keyword *aux, *ant; h = hashfun(bp->str); - if (!(aux = khash[h])) { + if (!(aux = khash[h]) || strcmp(bp->str, aux->str) < 0) { khash[h] = bp; + bp->next = aux; continue; } - ant = aux; - while (aux && strcmp(bp->str, aux->str) < 0) { - ant = aux; - aux = aux->next; + for (ant = aux; aux; ant = aux, aux = aux->next) { + if (strcmp(bp->str, aux->str) < 0) + break; } ant->next = bp; bp->next = aux;