diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-08-12 06:32:46 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-08-12 06:32:46 +0300 |
commit | 70bc75567b2ea3e0309b9171168bc1d2c1cadf43 (patch) | |
tree | 8b83a3e9a70d89e0fe24e6a80598fb996d6b291d /eval.c | |
parent | 52c0756d5d49d1077035167f50a15c8b952d0f69 (diff) | |
parent | 1be1a93e63a7ff6b45c7c20908df8bfd2a86c1be (diff) | |
download | egawk-70bc75567b2ea3e0309b9171168bc1d2c1cadf43.tar.gz egawk-70bc75567b2ea3e0309b9171168bc1d2c1cadf43.tar.bz2 egawk-70bc75567b2ea3e0309b9171168bc1d2c1cadf43.zip |
Merge branch 'gawk-4.1-stable'
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 30 |
1 files changed, 28 insertions, 2 deletions
@@ -803,9 +803,35 @@ set_BINMODE() void set_OFS() { + static bool first = true; + size_t new_ofs_len; + + if (first) /* true when called from init_vars() in main() */ + first = false; + else { + /* rebuild $0 using OFS that was current when $0 changed */ + if (! field0_valid) { + get_field(UNLIMITED - 1, NULL); + rebuild_record(); + } + } + + /* + * Save OFS value for use in building record and in printing. + * Can't just have OFS point into the OFS_node since it's + * already updated when we come into this routine, and we need + * the old value to rebuild the record (see above). + */ OFS_node->var_value = force_string(OFS_node->var_value); - OFS = OFS_node->var_value->stptr; - OFSlen = OFS_node->var_value->stlen; + new_ofs_len = OFS_node->var_value->stlen; + + if (OFS == NULL) + emalloc(OFS, char *, new_ofs_len + 2, "set_OFS"); + else if (OFSlen < new_ofs_len) + erealloc(OFS, char *, new_ofs_len + 2, "set_OFS"); + + memcpy(OFS, OFS_node->var_value->stptr, OFS_node->var_value->stlen); + OFSlen = new_ofs_len; OFS[OFSlen] = '\0'; } |