diff options
author | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2016-07-05 16:49:05 -0400 |
---|---|---|
committer | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2016-07-05 16:49:05 -0400 |
commit | f421a5fbef014040712a7c89e8863c7196f6ab93 (patch) | |
tree | 22a9544211a974bf155e5971d33c89a9796b93a5 /field.c | |
parent | cedd0829b0075533986fce1e699bc6ae511a891e (diff) | |
download | egawk-f421a5fbef014040712a7c89e8863c7196f6ab93.tar.gz egawk-f421a5fbef014040712a7c89e8863c7196f6ab93.tar.bz2 egawk-f421a5fbef014040712a7c89e8863c7196f6ab93.zip |
Remove FIELD flag, since it is the inverse of the MALLOC flag.
Diffstat (limited to 'field.c')
-rw-r--r-- | field.c | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -93,7 +93,7 @@ init_fields() getnode(Null_field); *Null_field = *Nnull_string; Null_field->valref = 1; - Null_field->flags = (FIELD|STRCUR|STRING|NULL_FIELD); + Null_field->flags = (STRCUR|STRING|NULL_FIELD); /* do not set MALLOC */ field0_valid = true; } @@ -131,7 +131,7 @@ set_field(long num, n = fields_arr[num]; n->stptr = str; n->stlen = len; - n->flags = (STRCUR|STRING|MAYBE_NUM|FIELD); + n->flags = (STRCUR|STRING|MAYBE_NUM); /* do not set MALLOC */ } /* rebuild_record --- Someone assigned a value to $(something). @@ -198,7 +198,7 @@ rebuild_record() NODE *n; getnode(n); - if ((r->flags & FIELD) == 0) { + if ((r->flags & MALLOC) != 0) { *n = *Null_field; n->stlen = r->stlen; if ((r->flags & (NUMCUR|NUMBER)) != 0) { @@ -216,7 +216,19 @@ rebuild_record() } } else { *n = *r; - n->flags &= ~MALLOC; + if (r->valref > 1) { + /* + * XXX This probably should never + * happen, but we can't leave r with + * stptr pointing into the old $0 + * buffer. Perhaps we should issue a + * warning message about memory + * corruption... + */ + emalloc(r->stptr, char *, r->stlen + 1, "rebuild_record"); + memcpy(r->stptr, cops, r->stlen); + r->stptr[r->stlen] = '\0'; + } } n->stptr = cops; @@ -289,7 +301,7 @@ set_record(const char *buf, int cnt) n->valref = 1; n->type = Node_val; n->stfmt = STFMT_UNUSED; - n->flags = (STRING|STRCUR|MAYBE_NUM|FIELD); + n->flags = (STRING|STRCUR|MAYBE_NUM); /* do not set MALLOC */ fields_arr[0] = n; #undef INITIAL_SIZE |