~sircmpwn/koio

d54874d52190d434ae36a7797e1259047202183d — Seth Hall 4 years ago feccec6
Fix hash collision error in hashtable.c

Also fixes a possible NULL dereference.
1 files changed, 4 insertions(+), 6 deletions(-)

M lib/hashtable.c
M lib/hashtable.c => lib/hashtable.c +4 -6
@@ 21,7 21,7 @@ void *ko_hashtable_get(struct ko_hashtable *table, const char *key) {
	unsigned int bucket = hash % buckets_size;
	struct ko_hashtable_entry *entry = table->buckets[bucket];
	if (entry) {
		if (entry->hash != hash) {
		if (entry->hash != hash || strcmp(entry->key, key) != 0) {
			while (entry->next) {
				entry = entry->next;
				if (!entry || (entry->hash == hash &&


@@ 30,10 30,8 @@ void *ko_hashtable_get(struct ko_hashtable *table, const char *key) {
				}
			}
		}
	} else {
		return NULL;
	}
	return entry->value;
	return entry ? entry->value : NULL;
}

void *ko_hashtable_set(struct ko_hashtable *table, const char *key, void *value) {


@@ 43,7 41,7 @@ void *ko_hashtable_set(struct ko_hashtable *table, const char *key, void *value)
	struct ko_hashtable_entry *previous = NULL;

	if (entry) {
		if (entry->hash != hash) {
		if (entry->hash != hash || strcmp(entry->key, key) != 0) {
			while (entry->next) {
				previous = entry;
				entry = entry->next;


@@ 77,7 75,7 @@ void *ko_hashtable_del(struct ko_hashtable *table, const void *key) {
	struct ko_hashtable_entry *previous = NULL;

	if (entry) {
		if (entry->hash != hash) {
		if (entry->hash != hash || strcmp(entry->key, key) != 0) {
			while (entry->next) {
				previous = entry;
				entry = entry->next;