summaryrefslogtreecommitdiff
path: root/choices.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2014-09-16 19:05:26 -0700
committerJohn Hawthorn <john.hawthorn@gmail.com>2014-09-16 19:05:34 -0700
commit10714ebd1c9688624216dc22ed65216d4032a45e (patch)
tree9a988a613fd324946f2d0824f97c29526f80738f /choices.c
parent28980ca3281d4c7ee81bf13e1082b7e27c83bd39 (diff)
Abort on allocation errors
Diffstat (limited to 'choices.c')
-rw-r--r--choices.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/choices.c b/choices.c
index 933b8a0..d1eaa3c 100644
--- a/choices.c
+++ b/choices.c
@@ -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;
}