morenice / ahocorasick

C implementation Aho-Corasick string matching
MIT License
23 stars 7 forks source link

seg fault on sample_code3 #3

Open ghost opened 5 years ago

ghost commented 5 years ago

These lines cause the segmentation fault

id[0] = aho_add_match_text(&aho, "consectetur", strlen("consectetur"));
id[1] = aho_add_match_text(&aho, "Proin", strlen("Proin"));
id[2] = aho_add_match_text(&aho, "egestasAliquam", strlen("egestasAliquam"));
id[3] = aho_add_match_text(&aho, "elementum", strlen("elementum"));
id[4] = aho_add_match_text(&aho, "ultricies", strlen("ultricies"));
id[5] = aho_add_match_text(&aho, "vehicula", strlen("vehicula"));
ghost commented 5 years ago

Swapping the last two lines gets rid of the seg fault:

id[0] = aho_add_match_text(&aho, "consectetur", strlen("consectetur"));
id[1] = aho_add_match_text(&aho, "Proin", strlen("Proin"));
id[2] = aho_add_match_text(&aho, "egestasAliquam", strlen("egestasAliquam"));
id[3] = aho_add_match_text(&aho, "elementum", strlen("elementum"));
id[5] = aho_add_match_text(&aho, "vehicula", strlen("vehicula"));
id[4] = aho_add_match_text(&aho, "ultricies", strlen("ultricies"));
morenice commented 5 years ago

I was busy. so I don't check it now. But this month, check out it.

Thanks for your concern.

atriviality commented 5 years ago

See pull request https://github.com/morenice/ahocorasick/pull/6. There is an edge case that causes a suffix link to be null; this in turn causes the segfault when looking for matches.