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++;