Skip to content
Snippets Groups Projects
Commit 79a731ba authored by schneider's avatar schneider
Browse files

fix(config): only fail with assert in slot allocation

parent b8987dd0
No related branches found
No related tags found
1 merge request!339New config api with support for dynamic keys
...@@ -67,12 +67,13 @@ static config_slot *allocate_config_slot() ...@@ -67,12 +67,13 @@ static config_slot *allocate_config_slot()
if (config_data == NULL) { if (config_data == NULL) {
config_data = malloc(sizeof(config_block)); config_data = malloc(sizeof(config_block));
assert(config_data != NULL);
memset(config_data, 0, sizeof(config_block)); memset(config_data, 0, sizeof(config_block));
} }
current = config_data; current = config_data;
while (current) { while (true) {
for (int i = 0; i < KEYS_PER_BLOCK; i++) { for (int i = 0; i < KEYS_PER_BLOCK; i++) {
config_slot *k = &current->slots[i]; config_slot *k = &current->slots[i];
if (*k->key == '\0') { if (*k->key == '\0') {
...@@ -83,12 +84,11 @@ static config_slot *allocate_config_slot() ...@@ -83,12 +84,11 @@ static config_slot *allocate_config_slot()
// this block is full and there's no next allocated block // this block is full and there's no next allocated block
if (current->next == NULL) { if (current->next == NULL) {
current->next = malloc(sizeof(config_block)); current->next = malloc(sizeof(config_block));
current = current->next; assert(current->next != NULL);
memset(current, 0, sizeof(config_block)); memset(current->next, 0, sizeof(config_block));
} }
current = current->next;
} }
return NULL;
} }
// parses an int out of 'value' or returns NOT_INT_MAGIC // parses an int out of 'value' or returns NOT_INT_MAGIC
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment