diff options
| author | Bartek Fabiszewski <bfabiszewski@users.noreply.github.com> | 2017-11-27 12:19:26 +0100 |
|---|---|---|
| committer | phajdan <phajdan.jr@gmail.com> | 2017-11-27 12:19:26 +0100 |
| commit | 73dd2967c8e1e4f6d7334ee9e539a323d6e66cbd (patch) | |
| tree | b70d1cd362b07aaf1694195ded0d2179dfa69135 /hyphen.c | |
| parent | a8d50da0cc93a28fa05bd892f49bf074e11280e6 (diff) | |
| download | hyphen-master.tar.gz | |
* Discard too long lines in dictionary file
* Discard too long lines in dictionary file: add warning and test
Diffstat (limited to 'hyphen.c')
| -rw-r--r-- | hyphen.c | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -438,11 +438,25 @@ for (k = 0; k < 2; k++) { } if (k == 0 || nextlevel) { - while (fgets (buf, sizeof(buf), f) != NULL) { + while (fgets(buf, sizeof(buf), f) != NULL) { + + /* discard lines that don't fit in buffer */ + if (!feof(f) && strchr(buf, '\n') == NULL) { + int c; + while ((c = fgetc(f)) != '\n' && c != EOF); + /* issue warning if not a comment */ + if (buf[0] != '%') { + fprintf(stderr, "Warning: skipping too long pattern (more than %lu chars)\n", sizeof(buf)); + } + continue; + } + if (strncmp(buf, "NEXTLEVEL", 9) == 0) { - nextlevel = 1; - break; - } else if (buf[0] != '%') hnj_hyphen_load_line(buf, dict[k], hashtab); + nextlevel = 1; + break; + } else if (buf[0] != '%') { + hnj_hyphen_load_line(buf, dict[k], hashtab); + } } } else if (k == 1) { /* default first level: hyphen and ASCII apostrophe */ |
