mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-27 18:50:07 +03:00
hash: Fix false positive from -fanalyzer
This commit is contained in:
parent
b349225952
commit
e91061eb9f
30
dict.c
30
dict.c
@ -700,7 +700,7 @@ xmlDictLookupInternal(xmlDictPtr dict, const xmlChar *prefix,
|
||||
const xmlChar *name, int maybeLen, int update) {
|
||||
xmlDictEntry *entry = NULL;
|
||||
const xmlChar *ret;
|
||||
unsigned hashValue;
|
||||
unsigned hashValue, newSize;
|
||||
size_t maxLen, len, plen, klen;
|
||||
int found = 0;
|
||||
|
||||
@ -727,10 +727,21 @@ xmlDictLookupInternal(xmlDictPtr dict, const xmlChar *prefix,
|
||||
/*
|
||||
* Check for an existing entry
|
||||
*/
|
||||
if (dict->size > 0)
|
||||
if (dict->size == 0) {
|
||||
newSize = MIN_HASH_SIZE;
|
||||
} else {
|
||||
entry = xmlDictFindEntry(dict, prefix, name, klen, hashValue, &found);
|
||||
if (found)
|
||||
return(entry);
|
||||
if (found)
|
||||
return(entry);
|
||||
|
||||
if (dict->nbElems + 1 > dict->size / MAX_FILL_DENOM * MAX_FILL_NUM) {
|
||||
if (dict->size >= MAX_HASH_SIZE)
|
||||
return(NULL);
|
||||
newSize = dict->size * 2;
|
||||
} else {
|
||||
newSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ((dict->subdict != NULL) && (dict->subdict->size > 0)) {
|
||||
xmlDictEntry *subEntry;
|
||||
@ -754,16 +765,9 @@ xmlDictLookupInternal(xmlDictPtr dict, const xmlChar *prefix,
|
||||
/*
|
||||
* Grow the hash table if needed
|
||||
*/
|
||||
if (dict->nbElems + 1 > dict->size / MAX_FILL_DENOM * MAX_FILL_NUM) {
|
||||
unsigned newSize, mask, displ, pos;
|
||||
if (newSize > 0) {
|
||||
unsigned mask, displ, pos;
|
||||
|
||||
if (dict->size == 0) {
|
||||
newSize = MIN_HASH_SIZE;
|
||||
} else {
|
||||
if (dict->size >= MAX_HASH_SIZE)
|
||||
return(NULL);
|
||||
newSize = dict->size * 2;
|
||||
}
|
||||
if (xmlDictGrow(dict, newSize) != 0)
|
||||
return(NULL);
|
||||
|
||||
|
47
hash.c
47
hash.c
@ -428,42 +428,49 @@ xmlHashUpdateInternal(xmlHashTablePtr hash, const xmlChar *key,
|
||||
xmlChar *copy, *copy2, *copy3;
|
||||
xmlHashEntry *entry = NULL;
|
||||
size_t lengths[3] = {0, 0, 0};
|
||||
unsigned hashValue;
|
||||
int found = 0;
|
||||
unsigned hashValue, newSize;
|
||||
|
||||
if ((hash == NULL) || (key == NULL))
|
||||
return(-1);
|
||||
|
||||
hashValue = xmlHashValue(hash->randomSeed, key, key2, key3, lengths);
|
||||
|
||||
/*
|
||||
* Check for an existing entry
|
||||
*/
|
||||
hashValue = xmlHashValue(hash->randomSeed, key, key2, key3, lengths);
|
||||
if (hash->size > 0)
|
||||
if (hash->size == 0) {
|
||||
newSize = MIN_HASH_SIZE;
|
||||
} else {
|
||||
int found = 0;
|
||||
|
||||
entry = xmlHashFindEntry(hash, key, key2, key3, hashValue, &found);
|
||||
if (found) {
|
||||
if (update) {
|
||||
if (dealloc)
|
||||
dealloc(entry->payload, entry->key);
|
||||
entry->payload = payload;
|
||||
|
||||
if (found) {
|
||||
if (update) {
|
||||
if (dealloc)
|
||||
dealloc(entry->payload, entry->key);
|
||||
entry->payload = payload;
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
return(0);
|
||||
if (hash->nbElems + 1 > hash->size / MAX_FILL_DENOM * MAX_FILL_NUM) {
|
||||
/* This guarantees that nbElems < INT_MAX */
|
||||
if (hash->size >= MAX_HASH_SIZE)
|
||||
return(-1);
|
||||
newSize = hash->size * 2;
|
||||
} else {
|
||||
newSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Grow the hash table if needed
|
||||
*/
|
||||
if (hash->nbElems + 1 > hash->size / MAX_FILL_DENOM * MAX_FILL_NUM) {
|
||||
unsigned newSize, mask, displ, pos;
|
||||
if (newSize > 0) {
|
||||
unsigned mask, displ, pos;
|
||||
|
||||
if (hash->size == 0) {
|
||||
newSize = MIN_HASH_SIZE;
|
||||
} else {
|
||||
/* This guarantees that nbElems < INT_MAX */
|
||||
if (hash->size >= MAX_HASH_SIZE)
|
||||
return(-1);
|
||||
newSize = hash->size * 2;
|
||||
}
|
||||
if (xmlHashGrow(hash, newSize) != 0)
|
||||
return(-1);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user