summaryrefslogtreecommitdiff
path: root/field.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2017-04-12 23:25:51 +0300
committerArnold D. Robbins <arnold@skeeve.com>2017-04-12 23:25:51 +0300
commit92f4d54776e4183a81209a9ce3a28f052f9249e4 (patch)
tree4fd680200eec236aa1c418aa1a2c07fbda1f30ad /field.c
parentec0c2d411eac8362f18572b2d8bd8617368b3ca6 (diff)
downloadgawk-92f4d54776e4183a81209a9ce3a28f052f9249e4.tar.gz
Fix valgrind invalid read issues in new fpat parsing.
Diffstat (limited to 'field.c')
-rw-r--r--field.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/field.c b/field.c
index 8145141c..608be7da 100644
--- a/field.c
+++ b/field.c
@@ -1581,7 +1581,7 @@ fpat_parse_field(long up_to, /* parse only up to this field number */
int regex_flags = RE_NEED_START;
mbstate_t mbs;
char* field_start;
- bool field_found;
+ bool field_found = false;
memset(&mbs, 0, sizeof(mbstate_t));
@@ -1594,7 +1594,7 @@ fpat_parse_field(long up_to, /* parse only up to this field number */
if (rp == NULL) /* use FPAT */
rp = FPAT_regexp;
- while (scan <= end && nf < up_to) { /* still something to parse */
+ while (scan < end && nf < up_to) { /* still something to parse */
/* first attempt to match the next field */
start = scan;
@@ -1632,10 +1632,17 @@ fpat_parse_field(long up_to, /* parse only up to this field number */
*/
if (sep_arr != NULL)
set_element(nf, start, (long) (end - start), sep_arr);
- scan = end + 1;
+ scan = end;
}
}
+ /*
+ * If the last field extends up to the end of the record, generate
+ * a null trailing separator
+ */
+ if (sep_arr != NULL && scan == end && field_found)
+ set_element(nf, scan, 0L, sep_arr);
+
*buf = scan;
return nf;
}