From 443fef666c786d75088f72a8e4c4172193eee3c0 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sun, 8 May 2016 22:47:18 -0400 Subject: [PATCH] Improved EOF handling for CSV; fixes #102 --- c/input/lrec_reader_mmap_csv.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/c/input/lrec_reader_mmap_csv.c b/c/input/lrec_reader_mmap_csv.c index 36807009cb..c0db58d1f5 100644 --- a/c/input/lrec_reader_mmap_csv.c +++ b/c/input/lrec_reader_mmap_csv.c @@ -215,6 +215,11 @@ static int lrec_reader_mmap_csv_get_fields(lrec_reader_mmap_csv_state_t* pstate, // Loop over characters in field field_done = FALSE; while (!field_done) { + if (e > phandle->eof) { + fprintf(stderr, "%s: internal coding error detected at line %d of file %s.\n", + MLR_GLOBALS.argv0, __LINE__, __FILE__); + exit(1); + } rc = parse_trie_match(pstate->pno_dquote_parse_trie, e, phandle->eof, &stridx, &matchlen); if (rc) { switch(stridx) { @@ -273,6 +278,11 @@ static int lrec_reader_mmap_csv_get_fields(lrec_reader_mmap_csv_state_t* pstate, // we use the string-build logic to build up a dynamically allocated string. E.g. // "ab""c" becomes ab"c. while (!field_done) { + if (e >= phandle->eof) { + fprintf(stderr, "%s: unmatched double quote at line %lld.\n", + MLR_GLOBALS.argv0, pstate->ilno); + exit(1); + } rc = parse_trie_match(pstate->pdquote_parse_trie, e, phandle->eof, &stridx, &matchlen);