Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explicit casts to *alloc and djb2 calls #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/rsht.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static unsigned long djb2(const unsigned char *str) {

// bool: did it work?
static bool setcapacity(rsht_ht *ht, const size_t capacity) {
rsht_entry *items = realloc(ht->items, capacity * sizeof(rsht_entry));
rsht_entry *items = (rsht_entry *)realloc(ht->items, capacity * sizeof(rsht_entry));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put a space between casts and things they cast?

if (!items) {
return false;
}
Expand All @@ -46,7 +46,7 @@ static bool setcapacity(rsht_ht *ht, const size_t capacity) {
// hint: only rsht_create should call this, and only once.
// bool: did it work?
static bool makebuckets(rsht_ht *ht, const size_t num_buckets) {
size_t *buckets = calloc(num_buckets, sizeof(size_t));
size_t *buckets = (size_t *)calloc(num_buckets, sizeof(size_t));
if (!buckets) {
return false;
}
Expand Down Expand Up @@ -111,11 +111,11 @@ rsht_entry *rsht_get_hash(const rsht_ht *ht, const char *key, const unsigned lon
}

rsht_entry *rsht_get(const rsht_ht *ht, const char *key) {
return rsht_get_hash(ht, key, djb2(key));
return rsht_get_hash(ht, key, djb2((const unsigned char *)key));
}

bool rsht_put(rsht_ht *ht, char *key, void *val, void **old_val_ref) {
const unsigned long hash = djb2(key);
const unsigned long hash = djb2((const unsigned char *)key);
rsht_entry *entry = rsht_get_hash(ht, key, hash);
if (entry) { // if we found it, swap the value into the entry
if (old_val_ref)
Expand Down