Fixed crashes when passed a NULL hashtable
This commit is contained in:
@@ -81,7 +81,7 @@ static SDL_INLINE Uint32 calc_hash(const SDL_HashTable *table, const void *key)
|
|||||||
SDL_bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const void *value)
|
SDL_bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const void *value)
|
||||||
{
|
{
|
||||||
SDL_HashItem *item;
|
SDL_HashItem *item;
|
||||||
const Uint32 hash = calc_hash(table, key);
|
Uint32 hash;
|
||||||
|
|
||||||
if (!table) {
|
if (!table) {
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
@@ -97,6 +97,8 @@ SDL_bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const vo
|
|||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hash = calc_hash(table, key);
|
||||||
|
|
||||||
item->key = key;
|
item->key = key;
|
||||||
item->value = value;
|
item->value = value;
|
||||||
item->next = table->table[hash];
|
item->next = table->table[hash];
|
||||||
@@ -107,14 +109,17 @@ SDL_bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const vo
|
|||||||
|
|
||||||
SDL_bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const void **_value)
|
SDL_bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const void **_value)
|
||||||
{
|
{
|
||||||
const Uint32 hash = calc_hash(table, key);
|
Uint32 hash;
|
||||||
void *data = table->data;
|
void *data;
|
||||||
SDL_HashItem *i;
|
SDL_HashItem *i;
|
||||||
|
|
||||||
if (!table) {
|
if (!table) {
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hash = calc_hash(table, key);
|
||||||
|
data = table->data;
|
||||||
|
|
||||||
for (i = table->table[hash]; i; i = i->next) {
|
for (i = table->table[hash]; i; i = i->next) {
|
||||||
if (table->keymatch(key, i->key, data)) {
|
if (table->keymatch(key, i->key, data)) {
|
||||||
if (_value) {
|
if (_value) {
|
||||||
@@ -129,15 +134,18 @@ SDL_bool SDL_FindInHashTable(const SDL_HashTable *table, const void *key, const
|
|||||||
|
|
||||||
SDL_bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key)
|
SDL_bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key)
|
||||||
{
|
{
|
||||||
const Uint32 hash = calc_hash(table, key);
|
Uint32 hash;
|
||||||
SDL_HashItem *item = NULL;
|
SDL_HashItem *item = NULL;
|
||||||
SDL_HashItem *prev = NULL;
|
SDL_HashItem *prev = NULL;
|
||||||
void *data = table->data;
|
void *data;
|
||||||
|
|
||||||
if (!table) {
|
if (!table) {
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hash = calc_hash(table, key);
|
||||||
|
data = table->data;
|
||||||
|
|
||||||
for (item = table->table[hash]; item; item = item->next) {
|
for (item = table->table[hash]; item; item = item->next) {
|
||||||
if (table->keymatch(key, item->key, data)) {
|
if (table->keymatch(key, item->key, data)) {
|
||||||
if (prev) {
|
if (prev) {
|
||||||
@@ -161,12 +169,14 @@ SDL_bool SDL_RemoveFromHashTable(SDL_HashTable *table, const void *key)
|
|||||||
|
|
||||||
SDL_bool SDL_IterateHashTableKey(const SDL_HashTable *table, const void *key, const void **_value, void **iter)
|
SDL_bool SDL_IterateHashTableKey(const SDL_HashTable *table, const void *key, const void **_value, void **iter)
|
||||||
{
|
{
|
||||||
SDL_HashItem *item = *iter ? ((SDL_HashItem *) *iter)->next : table->table[calc_hash(table, key)];
|
SDL_HashItem *item;
|
||||||
|
|
||||||
if (!table) {
|
if (!table) {
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item = *iter ? ((SDL_HashItem *)*iter)->next : table->table[calc_hash(table, key)];
|
||||||
|
|
||||||
while (item) {
|
while (item) {
|
||||||
if (table->keymatch(key, item->key, table->data)) {
|
if (table->keymatch(key, item->key, table->data)) {
|
||||||
*_value = item->value;
|
*_value = item->value;
|
||||||
|
|||||||
Reference in New Issue
Block a user