Skip to content

Commit

Permalink
Merge pull request #16 from d06alexandrov/read_regexp_file_fix
Browse files Browse the repository at this point in the history
Fixed reading regular expression files
  • Loading branch information
d06alexandrov committed Aug 7, 2023
2 parents abcdac2 + 6887d85 commit 6e4b668
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions tools/re2fa.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,14 @@ int main(int argc, char **argv)
} else {
regexp_cnt = 0;
for (int i = 0; i < arguments.input_cnt; i++) {
#define REGEXP_BUFFER_SIZE (1024 * 16)
FILE *file;
char buffer[REGEXP_BUFFER_SIZE];
char *next_regexp;
file = fopen(arguments.input[i], "r");
if (file == NULL)
continue;
while (fgets(buffer, REGEXP_BUFFER_SIZE, file) != NULL) {
if (strlen(buffer) == REGEXP_BUFFER_SIZE - 1) {
/* bad */
}
while (fscanf(file, "%ms", &next_regexp) == 1) {
regexp = realloc(regexp, sizeof(char *) * (regexp_cnt + 1));
regexp[regexp_cnt] = malloc(strlen(buffer) + 1);
memcpy(regexp[regexp_cnt], buffer,
strlen(buffer) + 1);
regexp[regexp_cnt] = next_regexp;
regexp_cnt++;
}
fclose(file);
Expand Down

0 comments on commit 6e4b668

Please sign in to comment.