Use runtime asserts on allocation success in parse.c
This commit is contained in:
19
lib/parse.c
19
lib/parse.c
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "parse.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define CLASS_START_CAPACITY 4
|
||||
@@ -62,15 +63,13 @@ static int parse_class(const char *input, int rem, regex_class_t *out)
|
||||
out->count = 0;
|
||||
out->capacity = CLASS_START_CAPACITY;
|
||||
out->contents = malloc(out->capacity);
|
||||
if (NULL == out->contents)
|
||||
return -1;
|
||||
assert(NULL != out->contents);
|
||||
|
||||
while (used < rem) {
|
||||
if (out->count >= out->capacity) {
|
||||
out->capacity *= 2;
|
||||
out->contents = realloc(out->contents, out->capacity);
|
||||
if (NULL == out->contents)
|
||||
return -1;
|
||||
assert(NULL != out->contents);
|
||||
}
|
||||
|
||||
result = parse_literal(
|
||||
@@ -155,16 +154,14 @@ static int parse_sequence(const char *input, int rem, regex_sequence_t *out)
|
||||
out->count = 0;
|
||||
out->capacity = SEQUENCE_START_CAPACITY;
|
||||
out->contents = malloc(out->capacity * sizeof(regex_term_t));
|
||||
if (NULL == out->contents)
|
||||
return -1;
|
||||
assert(NULL != out->contents);
|
||||
|
||||
while (used < rem) {
|
||||
if (out->count >= out->capacity) {
|
||||
out->capacity *= 2;
|
||||
out->contents = realloc(
|
||||
out->contents, out->capacity * sizeof(regex_term_t));
|
||||
if (NULL == out->contents)
|
||||
return -1;
|
||||
assert(NULL != out->contents);
|
||||
}
|
||||
|
||||
result = parse_term(
|
||||
@@ -185,8 +182,7 @@ int parse_expr(const char *input, int rem, regex_t *out)
|
||||
out->count = 0;
|
||||
out->capacity = TREE_START_CAPACITY;
|
||||
out->contents = malloc(out->capacity * sizeof(regex_sequence_t));
|
||||
if (NULL == out->contents)
|
||||
return -1;
|
||||
assert(NULL != out->contents);
|
||||
|
||||
result = parse_sequence(input + used, rem - used, &out->contents[0]);
|
||||
if (result < 0)
|
||||
@@ -203,8 +199,7 @@ int parse_expr(const char *input, int rem, regex_t *out)
|
||||
out->capacity *= 2;
|
||||
out->contents = realloc(
|
||||
out->contents, out->capacity * sizeof(regex_sequence_t));
|
||||
if (NULL == out->contents)
|
||||
return -1;
|
||||
assert(NULL != out->contents);
|
||||
}
|
||||
|
||||
result = parse_sequence(
|
||||
|
||||
Reference in New Issue
Block a user