Unverified Commit fe359cbf authored by Yossi Gottlieb's avatar Yossi Gottlieb Committed by GitHub
Browse files

Fix: don't assume char is unsigned. (#9375)

On systems that have unsigned char by default (s390x, arm), redis-server
could crash as soon as it populates the command table.
parent 8edc3cd6
...@@ -61,7 +61,7 @@ static unsigned int dict_force_resize_ratio = 5; ...@@ -61,7 +61,7 @@ static unsigned int dict_force_resize_ratio = 5;
/* -------------------------- private prototypes ---------------------------- */ /* -------------------------- private prototypes ---------------------------- */
static int _dictExpandIfNeeded(dict *d); static int _dictExpandIfNeeded(dict *d);
static char _dictNextExp(unsigned long size); static signed char _dictNextExp(unsigned long size);
static long _dictKeyIndex(dict *d, const void *key, uint64_t hash, dictEntry **existing); static long _dictKeyIndex(dict *d, const void *key, uint64_t hash, dictEntry **existing);
static int _dictInit(dict *d, dictType *type); static int _dictInit(dict *d, dictType *type);
...@@ -150,7 +150,7 @@ int _dictExpand(dict *d, unsigned long size, int* malloc_failed) ...@@ -150,7 +150,7 @@ int _dictExpand(dict *d, unsigned long size, int* malloc_failed)
/* the new hash table */ /* the new hash table */
dictEntry **new_ht_table; dictEntry **new_ht_table;
unsigned long new_ht_used; unsigned long new_ht_used;
char new_ht_size_exp = _dictNextExp(size); signed char new_ht_size_exp = _dictNextExp(size);
/* Detect overflows */ /* Detect overflows */
size_t newsize = 1ul<<new_ht_size_exp; size_t newsize = 1ul<<new_ht_size_exp;
...@@ -1009,7 +1009,7 @@ static int _dictExpandIfNeeded(dict *d) ...@@ -1009,7 +1009,7 @@ static int _dictExpandIfNeeded(dict *d)
/* TODO: clz optimization */ /* TODO: clz optimization */
/* Our hash table capability is a power of two */ /* Our hash table capability is a power of two */
static char _dictNextExp(unsigned long size) static signed char _dictNextExp(unsigned long size)
{ {
unsigned char e = DICT_HT_INITIAL_EXP; unsigned char e = DICT_HT_INITIAL_EXP;
......
...@@ -80,7 +80,7 @@ struct dict { ...@@ -80,7 +80,7 @@ struct dict {
/* Keep small vars at end for optimal (minimal) struct padding */ /* Keep small vars at end for optimal (minimal) struct padding */
int16_t pauserehash; /* If >0 rehashing is paused (<0 indicates coding error) */ int16_t pauserehash; /* If >0 rehashing is paused (<0 indicates coding error) */
char ht_size_exp[2]; /* exponent of size. (size = 1<<exp) */ signed char ht_size_exp[2]; /* exponent of size. (size = 1<<exp) */
}; };
/* If safe is set to 1 this is a safe iterator, that means, you can call /* If safe is set to 1 this is a safe iterator, that means, you can call
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment