Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. diff --git a/shared/hash.c b/shared/hash.c
  2. index ab8534a..18898ac 100644
  3. --- a/shared/hash.c
  4. +++ b/shared/hash.c
  5. @@ -137,8 +137,7 @@ static inline unsigned int hash_superfast(const char *key, unsigned int len)
  6. return hash;
  7. }
  8.  
  9. -static struct hash_entry *hash_add_entry(struct hash *hash,
  10. - const char *key, const void *value)
  11. +static struct hash_entry *hash_add_entry(struct hash *hash, const char *key)
  12. {
  13. unsigned int keylen = strlen(key);
  14. unsigned int hashval = hash_superfast(key, keylen);
  15. @@ -172,7 +171,8 @@ static struct hash_entry *hash_add_entry(struct hash *hash,
  16. bucket->used++;
  17. hash->count++;
  18.  
  19. - entry->key = entry->value = NULL;
  20. + entry->key = NULL;
  21. + entry->value = NULL;
  22.  
  23. return entry;
  24. }
  25. @@ -185,12 +185,12 @@ static struct hash_entry *hash_add_entry(struct hash *hash,
  26. */
  27. int hash_add(struct hash *hash, const char *key, const void *value)
  28. {
  29. - struct hash_entry *entry = hash_add_entry(hash, key, value);
  30. + struct hash_entry *entry = hash_add_entry(hash, key);
  31.  
  32. if (!entry)
  33. return -errno;
  34.  
  35. - if (hash->free_value)
  36. + if (hash->free_value && entry->value != NULL)
  37. hash->free_value((void *)entry->value);
  38.  
  39. entry->key = key;
  40. @@ -202,12 +202,12 @@ int hash_add(struct hash *hash, const char *key, const void *value)
  41. /* similar to hash_add(), but fails if key already exists */
  42. int hash_add_unique(struct hash *hash, const char *key, const void *value)
  43. {
  44. - struct hash_entry *entry = hash_add_entry(hash, key, value);
  45. + struct hash_entry *entry = hash_add_entry(hash, key);
  46.  
  47. if (!entry)
  48. return -errno;
  49.  
  50. - if (entry->key || entry->value)
  51. + if (entry->key)
  52. return -EEXIST;
  53.  
  54. entry->key = key;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement