From e4c527b0f07b91fb3cd9ba58ba057dfea9da9356 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Fri, 9 Aug 2019 09:20:53 +0100 Subject: check all mem allocations --- draw.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'draw.c') diff --git a/draw.c b/draw.c index 49fad1b..7e93e39 100644 --- a/draw.c +++ b/draw.c @@ -221,11 +221,16 @@ void get_arrow(FILE *fc){ char c; int orig_x=x, orig_y=y, arrow_len; static short *arrow = NULL; + short *tmp = NULL; static int arrow_sz; if (!arrow){ arrow_sz = 100; arrow = malloc(arrow_sz * sizeof(short)); + if (arrow == NULL){ + fprintf(stderr, "Unable to allocate arrow"); + cleanup(1); + } } arrow_len = 0; dir = DIR_N; @@ -242,7 +247,12 @@ void get_arrow(FILE *fc){ /* FIXME: if we are out of bound, do nothing? */ if (arrow_len == arrow_sz){ arrow_sz *=2; - arrow = realloc(arrow, arrow_sz * sizeof(short)); + tmp = realloc(arrow, arrow_sz * sizeof(short)); + if (tmp == NULL){ + fprintf(stderr, "Unable to reallocate arrow"); + cleanup(1); + } + arrow = tmp; } if (dir != DIR_N){ arrow[arrow_len++] = dir; -- cgit v1.2.3