From e25d9e0a43f36c93a18d0c075f3ee291d2fa1ed9 Mon Sep 17 00:00:00 2001 From: Felix Suchert Date: Sun, 25 Dec 2022 23:38:20 +0100 Subject: [PATCH] Fix TODO on day 1 --- day_1/parser.y | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/day_1/parser.y b/day_1/parser.y index 53d1e01..e33370a 100644 --- a/day_1/parser.y +++ b/day_1/parser.y @@ -23,8 +23,12 @@ #include "lexer.h" void push_value(struct parser_state* state) { - // TODO(feliix42): error handling here? - state->calorie_list = realloc(state->calorie_list, (state->size+1) * sizeof(unsigned long)); + unsigned long* resized = realloc(state->calorie_list, (state->size+1) * sizeof(unsigned long)); + if (!resized) { + fprintf(stderr, "\033[93m[error] Failed to allocate enough memory to resize the list of calories\033[0m\n"); + return; + } + state->calorie_list = resized; state->calorie_list[state->size] = state->tmp_val; state->tmp_val = 0; state->size++;