diff options
author | John Hawthorn <john.hawthorn@gmail.com> | 2014-09-16 19:05:26 -0700 |
---|---|---|
committer | John Hawthorn <john.hawthorn@gmail.com> | 2014-09-16 19:05:34 -0700 |
commit | 10714ebd1c9688624216dc22ed65216d4032a45e (patch) | |
tree | 9a988a613fd324946f2d0824f97c29526f80738f /choices.c | |
parent | 28980ca3281d4c7ee81bf13e1082b7e27c83bd39 (diff) |
Abort on allocation errors
Diffstat (limited to 'choices.c')
-rw-r--r-- | choices.c | 6 |
1 files changed, 6 insertions, 0 deletions
@@ -1,5 +1,6 @@ #define _GNU_SOURCE #include <stdlib.h> +#include <stdio.h> #include "choices.h" #include "match.h" @@ -23,6 +24,11 @@ static void choices_resize(choices_t *c, int new_capacity){ c->scores = realloc(c->scores, new_capacity * sizeof(double)); c->sorted = realloc(c->sorted, new_capacity * sizeof(size_t)); + if(!c->strings || !c->scores || !c->sorted){ + fprintf(stderr, "Error: Can't allocate memory\n"); + abort(); + } + for(int i = c->capacity; i < new_capacity; i++){ c->strings[i] = NULL; } |