Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

Commit e91061e

Browse files
committed
hash: Fix false positive from -fanalyzer
1 parent b349225 commit e91061e

2 files changed

Lines changed: 44 additions & 33 deletions

File tree

dict.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ xmlDictLookupInternal(xmlDictPtr dict, const xmlChar *prefix,
700700
const xmlChar *name, int maybeLen, int update) {
701701
xmlDictEntry *entry = NULL;
702702
const xmlChar *ret;
703-
unsigned hashValue;
703+
unsigned hashValue, newSize;
704704
size_t maxLen, len, plen, klen;
705705
int found = 0;
706706

@@ -727,10 +727,21 @@ xmlDictLookupInternal(xmlDictPtr dict, const xmlChar *prefix,
727727
/*
728728
* Check for an existing entry
729729
*/
730-
if (dict->size > 0)
730+
if (dict->size == 0) {
731+
newSize = MIN_HASH_SIZE;
732+
} else {
731733
entry = xmlDictFindEntry(dict, prefix, name, klen, hashValue, &found);
732-
if (found)
733-
return(entry);
734+
if (found)
735+
return(entry);
736+
737+
if (dict->nbElems + 1 > dict->size / MAX_FILL_DENOM * MAX_FILL_NUM) {
738+
if (dict->size >= MAX_HASH_SIZE)
739+
return(NULL);
740+
newSize = dict->size * 2;
741+
} else {
742+
newSize = 0;
743+
}
744+
}
734745

735746
if ((dict->subdict != NULL) && (dict->subdict->size > 0)) {
736747
xmlDictEntry *subEntry;
@@ -754,16 +765,9 @@ xmlDictLookupInternal(xmlDictPtr dict, const xmlChar *prefix,
754765
/*
755766
* Grow the hash table if needed
756767
*/
757-
if (dict->nbElems + 1 > dict->size / MAX_FILL_DENOM * MAX_FILL_NUM) {
758-
unsigned newSize, mask, displ, pos;
768+
if (newSize > 0) {
769+
unsigned mask, displ, pos;
759770

760-
if (dict->size == 0) {
761-
newSize = MIN_HASH_SIZE;
762-
} else {
763-
if (dict->size >= MAX_HASH_SIZE)
764-
return(NULL);
765-
newSize = dict->size * 2;
766-
}
767771
if (xmlDictGrow(dict, newSize) != 0)
768772
return(NULL);
769773

hash.c

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -428,42 +428,49 @@ xmlHashUpdateInternal(xmlHashTablePtr hash, const xmlChar *key,
428428
xmlChar *copy, *copy2, *copy3;
429429
xmlHashEntry *entry = NULL;
430430
size_t lengths[3] = {0, 0, 0};
431-
unsigned hashValue;
432-
int found = 0;
431+
unsigned hashValue, newSize;
433432

434433
if ((hash == NULL) || (key == NULL))
435434
return(-1);
436435

436+
hashValue = xmlHashValue(hash->randomSeed, key, key2, key3, lengths);
437+
437438
/*
438439
* Check for an existing entry
439440
*/
440-
hashValue = xmlHashValue(hash->randomSeed, key, key2, key3, lengths);
441-
if (hash->size > 0)
441+
if (hash->size == 0) {
442+
newSize = MIN_HASH_SIZE;
443+
} else {
444+
int found = 0;
445+
442446
entry = xmlHashFindEntry(hash, key, key2, key3, hashValue, &found);
443-
if (found) {
444-
if (update) {
445-
if (dealloc)
446-
dealloc(entry->payload, entry->key);
447-
entry->payload = payload;
448-
}
449447

450-
return(0);
451-
}
448+
if (found) {
449+
if (update) {
450+
if (dealloc)
451+
dealloc(entry->payload, entry->key);
452+
entry->payload = payload;
453+
}
452454

453-
/*
454-
* Grow the hash table if needed
455-
*/
456-
if (hash->nbElems + 1 > hash->size / MAX_FILL_DENOM * MAX_FILL_NUM) {
457-
unsigned newSize, mask, displ, pos;
455+
return(0);
456+
}
458457

459-
if (hash->size == 0) {
460-
newSize = MIN_HASH_SIZE;
461-
} else {
458+
if (hash->nbElems + 1 > hash->size / MAX_FILL_DENOM * MAX_FILL_NUM) {
462459
/* This guarantees that nbElems < INT_MAX */
463460
if (hash->size >= MAX_HASH_SIZE)
464461
return(-1);
465462
newSize = hash->size * 2;
463+
} else {
464+
newSize = 0;
466465
}
466+
}
467+
468+
/*
469+
* Grow the hash table if needed
470+
*/
471+
if (newSize > 0) {
472+
unsigned mask, displ, pos;
473+
467474
if (xmlHashGrow(hash, newSize) != 0)
468475
return(-1);
469476

0 commit comments

Comments
 (0)