summaryrefslogtreecommitdiff
path: root/hyphen.c
diff options
context:
space:
mode:
authorBartek Fabiszewski <bfabiszewski@users.noreply.github.com>2017-11-27 12:19:26 +0100
committerphajdan <phajdan.jr@gmail.com>2017-11-27 12:19:26 +0100
commit73dd2967c8e1e4f6d7334ee9e539a323d6e66cbd (patch)
treeb70d1cd362b07aaf1694195ded0d2179dfa69135 /hyphen.c
parenta8d50da0cc93a28fa05bd892f49bf074e11280e6 (diff)
downloadhyphen-master.tar.gz
Discard too long lines in dictionary file (#14)HEADmaster
* 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.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/hyphen.c b/hyphen.c
index 9a132d0..9f2b711 100644
--- a/hyphen.c
+++ b/hyphen.c
@@ -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 */