summaryrefslogtreecommitdiff
path: root/draw.c
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2019-08-09 09:20:53 +0100
committerKatolaZ <katolaz@freaknet.org>2019-08-09 09:20:53 +0100
commite4c527b0f07b91fb3cd9ba58ba057dfea9da9356 (patch)
tree9f6b3ed5ecc616d71d7d188a08eddccac94a75a7 /draw.c
parenta6f10d6541be679b0ca328ba85fa44d2935937cd (diff)
check all mem allocations
Diffstat (limited to 'draw.c')
-rw-r--r--draw.c12
1 files changed, 11 insertions, 1 deletions
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;