@@ -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