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
multiarch
Peter Johnson 17 years ago
parent 3e1f0390e2
commit dfa51bf888
  1. 10
      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;

Loading…
Cancel
Save