Browse code

Abort on allocation errors

John Hawthorn authored on 17/09/2014 02:05:26
Showing 1 changed files

... ...
@@ -1,5 +1,6 @@
1 1
 #define _GNU_SOURCE
2 2
 #include <stdlib.h>
3
+#include <stdio.h>
3 4
 
4 5
 #include "choices.h"
5 6
 #include "match.h"
... ...
@@ -23,6 +24,11 @@ static void choices_resize(choices_t *c, int new_capacity){
23 24
 	c->scores  = realloc(c->scores,  new_capacity * sizeof(double));
24 25
 	c->sorted  = realloc(c->sorted,  new_capacity * sizeof(size_t));
25 26
 
27
+	if(!c->strings || !c->scores || !c->sorted){
28
+		fprintf(stderr, "Error: Can't allocate memory\n");
29
+		abort();
30
+	}
31
+
26 32
 	for(int i = c->capacity; i < new_capacity; i++){
27 33
 		c->strings[i] = NULL;
28 34
 	}