From 79a731ba7a58754aaa47509aad86bc423a4c71d2 Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Sun, 10 Nov 2019 17:06:15 +0100 Subject: [PATCH] fix(config): only fail with assert in slot allocation --- epicardium/modules/config.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/epicardium/modules/config.c b/epicardium/modules/config.c index 4da4ea89..2e334db1 100644 --- a/epicardium/modules/config.c +++ b/epicardium/modules/config.c @@ -67,12 +67,13 @@ static config_slot *allocate_config_slot() if (config_data == NULL) { config_data = malloc(sizeof(config_block)); + assert(config_data != NULL); memset(config_data, 0, sizeof(config_block)); } current = config_data; - while (current) { + while (true) { for (int i = 0; i < KEYS_PER_BLOCK; i++) { config_slot *k = ¤t->slots[i]; if (*k->key == '\0') { @@ -83,12 +84,11 @@ static config_slot *allocate_config_slot() // this block is full and there's no next allocated block if (current->next == NULL) { current->next = malloc(sizeof(config_block)); - current = current->next; - memset(current, 0, sizeof(config_block)); + assert(current->next != NULL); + memset(current->next, 0, sizeof(config_block)); } + current = current->next; } - - return NULL; } // parses an int out of 'value' or returns NOT_INT_MAGIC -- GitLab