diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-08-12 21:58:24 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-08-12 21:58:24 +0300 |
commit | 8f2c2755573b81c1e2c9ef1c42c529d13396d4d2 (patch) | |
tree | 99eaa148631402d7fe600fdcd7ba402c74d13ff2 /eval.c | |
parent | 09dca22666681470a207083f339083a1a4a8c973 (diff) | |
parent | 9e2907afe246b3930d9ae6043a2657c4492f4507 (diff) | |
download | egawk-8f2c2755573b81c1e2c9ef1c42c529d13396d4d2.tar.gz egawk-8f2c2755573b81c1e2c9ef1c42c529d13396d4d2.tar.bz2 egawk-8f2c2755573b81c1e2c9ef1c42c529d13396d4d2.zip |
Merge branch 'master' into comment
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 30 |
1 files changed, 28 insertions, 2 deletions
@@ -804,9 +804,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'; } |