From: Peter Johnson Date: Tue, 31 Jul 2007 04:53:22 +0000 (-0000) Subject: Fix two bugs in HAMT: X-Git-Tag: v0.6.2~8^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dfa51bf88822a3e16e6c888cdd3a3a3196905d77;p=yasm Fix two bugs in HAMT: - HAMT_search() wasn't doing a full string comparison on the key before returning success. - HAMT_insert()'s check for the above was always doing a case-sensitive check; fixed to use case-insensitive when the HAMT is supposed to be case-insensitive (and likewise for HAMT_search). svn path=/trunk/yasm/; revision=1903 --- diff --git a/libyasm/hamt.c b/libyasm/hamt.c index dd28c544..033a48ac 100644 --- a/libyasm/hamt.c +++ b/libyasm/hamt.c @@ -56,6 +56,7 @@ struct HAMT { const char *message); unsigned long (*HashKey) (const char *key); unsigned long (*ReHashKey) (const char *key, int Level); + int (*CmpKey) (const char *s1, const char *s2); }; /* XXX make a portable version of this. This depends on the pointer being @@ -132,9 +133,11 @@ HAMT_create(int nocase, /*@exits@*/ void (*error_func) if (nocase) { hamt->HashKey = HashKey_nocase; hamt->ReHashKey = ReHashKey_nocase; + hamt->CmpKey = strcasecmp; } else { hamt->HashKey = HashKey; hamt->ReHashKey = ReHashKey; + hamt->CmpKey = strcmp; } return hamt; @@ -244,7 +247,8 @@ HAMT_insert(HAMT *hamt, const char *str, void *data, int *replace, for (;;) { if (!(IsSubTrie(node))) { if (node->BitMapKey == key - && strcmp(((HAMTEntry *)(node->BaseValue))->str, str) == 0) { + && hamt->CmpKey(((HAMTEntry *)(node->BaseValue))->str, + str) == 0) { /*@-branchstate@*/ if (*replace) { deletefunc(((HAMTEntry *)(node->BaseValue))->data); @@ -384,7 +388,9 @@ HAMT_search(HAMT *hamt, const char *str) for (;;) { if (!(IsSubTrie(node))) { - if (node->BitMapKey == key) + if (node->BitMapKey == key + && hamt->CmpKey(((HAMTEntry *)(node->BaseValue))->str, + str) == 0) return ((HAMTEntry *)(node->BaseValue))->data; else return NULL;