aboutsummaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-08-12 21:58:24 +0300
committerArnold D. Robbins <arnold@skeeve.com>2014-08-12 21:58:24 +0300
commit8f2c2755573b81c1e2c9ef1c42c529d13396d4d2 (patch)
tree99eaa148631402d7fe600fdcd7ba402c74d13ff2 /eval.c
parent09dca22666681470a207083f339083a1a4a8c973 (diff)
parent9e2907afe246b3930d9ae6043a2657c4492f4507 (diff)
downloadegawk-8f2c2755573b81c1e2c9ef1c42c529d13396d4d2.tar.gz
egawk-8f2c2755573b81c1e2c9ef1c42c529d13396d4d2.tar.bz2
egawk-8f2c2755573b81c1e2c9ef1c42c529d13396d4d2.zip
Merge branch 'master' into comment
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/eval.c b/eval.c
index 028f7fee..4fd4fc5e 100644
--- a/eval.c
+++ b/eval.c
@@ -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';
}