projects
/
m6w6
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
Merge Patrick's exception branch.
[m6w6/libmemcached]
/
libmemcached
/
memcached_hash.c
diff --git
a/libmemcached/memcached_hash.c
b/libmemcached/memcached_hash.c
index 5deb5c755f2708c353756125b31c43ac35b28a8b..4956d18e0655e784bbb4e7a4b3c0200d4552bb77 100644
(file)
--- a/
libmemcached/memcached_hash.c
+++ b/
libmemcached/memcached_hash.c
@@
-47,11
+47,11
@@
uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memca
break;
case MEMCACHED_HASH_FNV1A_64:
{
break;
case MEMCACHED_HASH_FNV1A_64:
{
- hash= FNV_64_INIT;
+ hash=
(uint32_t)
FNV_64_INIT;
for (x= 0; x < key_length; x++)
{
hash ^= key[x];
for (x= 0; x < key_length; x++)
{
hash ^= key[x];
- hash *= FNV_64_PRIME;
+ hash *=
(uint32_t)
FNV_64_PRIME;
}
}
break;
}
}
break;
@@
-146,7
+146,7
@@
static uint32_t dispatch_host(memcached_st *ptr, uint32_t hash)
case MEMCACHED_DISTRIBUTION_MODULA:
return hash % ptr->number_of_hosts;
case MEMCACHED_DISTRIBUTION_RANDOM:
case MEMCACHED_DISTRIBUTION_MODULA:
return hash % ptr->number_of_hosts;
case MEMCACHED_DISTRIBUTION_RANDOM:
- return random() % ptr->number_of_hosts;
+ return
(uint32_t)
random() % ptr->number_of_hosts;
default:
WATCHPOINT_ASSERT(0); /* We have added a distribution without extending the logic */
return hash % ptr->number_of_hosts;
default:
WATCHPOINT_ASSERT(0); /* We have added a distribution without extending the logic */
return hash % ptr->number_of_hosts;
@@
-170,12
+170,15
@@
uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_
if (ptr->flags & MEM_HASH_WITH_PREFIX_KEY)
{
if (ptr->flags & MEM_HASH_WITH_PREFIX_KEY)
{
- int temp_len= ptr->prefix_key_length + key_length;
- char *temp= (char *)malloc(temp_len);
+ size_t temp_length= ptr->prefix_key_length + key_length;
+ char temp[temp_length];
+
+ if (temp_length > MEMCACHED_MAX_KEY -1)
+ return 0;
+
strncpy(temp, ptr->prefix_key, ptr->prefix_key_length);
strncpy(temp + ptr->prefix_key_length, key, key_length);
strncpy(temp, ptr->prefix_key, ptr->prefix_key_length);
strncpy(temp + ptr->prefix_key_length, key, key_length);
- hash= generate_hash(ptr, temp, temp_len);
- free(temp);
+ hash= generate_hash(ptr, temp, temp_length);
}
else
{
}
else
{
@@
-202,7
+205,7
@@
static uint32_t internal_generate_hash(const char *key, size_t key_length)
while (key_length--)
{
while (key_length--)
{
- value += *ptr++;
+ value +=
(uint32_t)
*ptr++;
value += (value << 10);
value ^= (value >> 6);
}
value += (value << 10);
value ^= (value >> 6);
}
@@
-210,7
+213,7
@@
static uint32_t internal_generate_hash(const char *key, size_t key_length)
value ^= (value >> 11);
value += (value << 15);
value ^= (value >> 11);
value += (value << 15);
- return value == 0 ? 1 : value;
+ return value == 0 ? 1 :
(uint32_t)
value;
}
static uint32_t internal_generate_md5(const char *key, size_t key_length)
}
static uint32_t internal_generate_md5(const char *key, size_t key_length)