diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2017-04-12 23:32:03 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2017-04-12 23:32:03 +0300 |
commit | bbd26f5f61b1dae2d1638a45088105be616cf2fd (patch) | |
tree | 3ea5059ec653f606999ca0a72dbbc590ad435927 | |
parent | 8850b2870ae9665b302dd4d3035449a2a371ff27 (diff) | |
parent | 9fff07da8c25183f53934c0155d1fa49bc97198e (diff) | |
download | egawk-bbd26f5f61b1dae2d1638a45088105be616cf2fd.tar.gz egawk-bbd26f5f61b1dae2d1638a45088105be616cf2fd.tar.bz2 egawk-bbd26f5f61b1dae2d1638a45088105be616cf2fd.zip |
Merge branch 'master' into feature/api-mpfr
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | field.c | 13 | ||||
-rw-r--r-- | mpfr.c | 1 |
3 files changed, 17 insertions, 3 deletions
@@ -1,5 +1,8 @@ 2017-04-12 Arnold D. Robbins <arnold@skeeve.com> + * mpfr.c (mpg_format_val): Set STRCUR flag when we're done. + Fixes a memory leak. Thanks to valgrind for the report. + * gawkapi.c (awk_value_to_node): Initialize ext_ret_val to NULL to avoid compiler warnings. @@ -11,6 +14,9 @@ * field.c (fpat_parse_field): Restructure the code to reduce complexity and document the new structure. + * field.c (fpat_parse_field): Further restructuring to avoid + invalid reads as reported by valgrind. + 2017-04-10 Andrew J. Schorr <aschorr@telemetry-investments.com> * awk.h (enum opcodeval): For the avoidance of doubt, specify that @@ -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; } @@ -372,6 +372,7 @@ mpg_format_val(const char *format, int index, NODE *s) if ((s->flags & (MALLOC|STRCUR)) == (MALLOC|STRCUR)) efree(s->stptr); s->stptr = r->stptr; + s->flags |= STRCUR; freenode(r); /* Do not unref(r)! We want to keep s->stptr == r->stpr. */ free_wstr(s); return s; |