Fix allocation issue in FSA module
This commit is contained in:
@@ -33,7 +33,8 @@ int fsa_add_state(fsa_t *fsa)
|
||||
{
|
||||
if (fsa->count >= fsa->capacity) {
|
||||
fsa->capacity *= 2;
|
||||
fsa->states = realloc(fsa->states, fsa->capacity);
|
||||
fsa->states
|
||||
= realloc(fsa->states, fsa->capacity * sizeof(fsa_state_t));
|
||||
assert(NULL != fsa->states);
|
||||
}
|
||||
|
||||
@@ -56,7 +57,8 @@ void fsa_add_rule(fsa_t *fsa, int from, int to, int input)
|
||||
fsa_state_t *state = &fsa->states[from];
|
||||
if (state->count >= state->capacity) {
|
||||
state->capacity *= 2;
|
||||
state->rules = realloc(state->rules, state->capacity);
|
||||
state->rules
|
||||
= realloc(state->rules, state->capacity * sizeof(fsa_rule_t));
|
||||
assert(NULL != state->rules);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,17 @@ static void test_arbitrary_regex_2(void)
|
||||
fsa_free(&dfa);
|
||||
}
|
||||
|
||||
static void test_system_header_include_regex(void)
|
||||
{
|
||||
fsa_t dfa;
|
||||
const char *regex = "#include <[abcdefghijklmnopqrstuvwxyz]+\\.h>";
|
||||
const bool success = compile(regex, strlen(regex), &dfa);
|
||||
ASSERT_TRUE(success);
|
||||
ASSERT_ACCEPTS(&dfa, "#include <stdio.h>");
|
||||
ASSERT_REJECTS(&dfa, "#include \"foo.h\"");
|
||||
fsa_free(&dfa);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TESTING_BEGIN();
|
||||
@@ -70,5 +81,6 @@ int main(void)
|
||||
test_even_number_of_Is_regex();
|
||||
test_arbitrary_regex_1();
|
||||
test_arbitrary_regex_2();
|
||||
test_system_header_include_regex();
|
||||
return TESTING_END();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user