Skip to content

Commit

Permalink
GH-79 Resolve clobbered word variable reported on Linux and Cygwin.
Browse files Browse the repository at this point in the history
  • Loading branch information
SirWumpus committed Nov 29, 2024
1 parent 90990be commit 0a26e74
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions src/post4.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,6 @@ int
p4Repl(P4_Ctx *ctx, volatile int thrown)
{
int rc;
P4_Word *word;
P4_String str;
P4_Cell w, x, y, *ip;

Expand Down Expand Up @@ -1294,10 +1293,10 @@ p4Repl(P4_Ctx *ctx, volatile int thrown)

if (p4_builtin_words == NULL) {
/* Link up the base dictionary. */
for (word = words; word->code != NULL; word++) {
word[1].prev = word;
for (w.nt = words; w.nt->code != NULL; w.nt++) {
w.nt[1].prev = w.nt;
}
p4_builtin_words = word->prev;
p4_builtin_words = w.nt->prev;
*ctx->active = p4_builtin_words;
#ifdef HAVE_HOOKS
/* Find _hook_call and install any hooked words, eg. SH SHELL. */
Expand All @@ -1316,7 +1315,7 @@ p4Repl(P4_Ctx *ctx, volatile int thrown)

#define NEXT goto _next
#define THROWHARD(e) { rc = (e); goto _thrown; }
#define THROW(e) { if (p4_throw != NULL) { word = p4_throw; \
#define THROW(e) { if (p4_throw != NULL) { x.nt = p4_throw; \
P4_PUSH(ctx->ds, (P4_Int)(e)); \
/* Reset any previous exception. */ \
rc = P4_THROW_OK; goto _forth; \
Expand All @@ -1339,6 +1338,7 @@ p4Repl(P4_Ctx *ctx, volatile int thrown)

SETJMP_PUSH(ctx->longjmp);
rc = SETJMP(ctx->longjmp);

if (thrown != P4_THROW_OK) {
/* Signal thrown overrides context. */
rc = thrown;
Expand All @@ -1363,14 +1363,14 @@ p4Repl(P4_Ctx *ctx, volatile int thrown)
/* A thrown error while compiling a word leaves the
* definition in an incomplete state; discard it.
*/
word = *ctx->active;
w.nt = *ctx->active;
(void) fprintf(STDERR, " compiling %s",
word->length == 0 ? ":NONAME" : (char *)word->name
w.nt->length == 0 ? ":NONAME" : (char *)w.nt->name
);
*ctx->active = word->prev;
*ctx->active = w.nt->prev;
/* Rewind HERE, does not free ALLOCATE data. */
ctx->here = (P4_Char *) word->data;
p4WordFree(word);
ctx->here = (P4_Char *) w.nt->data;
p4WordFree(w.nt);
} else {
/* Cannot rely on ip pointint to the xt after the error. */
(void) fprintf(STDERR, "\r\ninput: "ANSI_UNDERLINE"%*s"ANSI_NORMAL,
Expand Down Expand Up @@ -1425,8 +1425,8 @@ _inter_loop: while (ctx->input->offset < ctx->input->length) {
if (str.length == 0) {
break;
}
word = p4FindName(ctx, str.string, str.length);
if (word == NULL) {
x.nt = p4FindName(ctx, str.string, str.length);
if (x.nt == NULL) {
P4_Cell num[2];
int is_float, is_double;
if (p4StrNum(str, ctx->radix, num, &is_float, &is_double)) {
Expand Down Expand Up @@ -1467,12 +1467,12 @@ _inter_loop: while (ctx->input->offset < ctx->input->length) {
P4_PUSH(ctx->ds, num[1]);
}
}
} else if (ctx->state == P4_STATE_INTERPRET && P4_WORD_IS(word, P4_BIT_COMPILE)) {
} else if (ctx->state == P4_STATE_INTERPRET && P4_WORD_IS(x.nt, P4_BIT_COMPILE)) {
THROW(P4_THROW_COMPILE_ONLY);
} else if (ctx->state == P4_STATE_COMPILE && !P4_WORD_IS_IMM(word)) {
p4WordAppend(ctx, (P4_Cell) word);
} else if (ctx->state == P4_STATE_COMPILE && !P4_WORD_IS_IMM(x.nt)) {
p4WordAppend(ctx, (P4_Cell) x.nt);
} else {
_forth: exec[0].xt = word;
_forth: exec[0].xt = x.nt;
ip = exec;
NEXT;
}
Expand Down Expand Up @@ -1603,16 +1603,16 @@ _do_colon: ctx->state = P4_STATE_COMPILE;
if (ctx->trace) {
(void) printf("%*s%.*s\r\n", 19+2*(int)ctx->level, "", (int)str.length, str.string);
}
p4AllocStack(ctx, &ctx->ds, 1+(word->length == 0));
word = p4WordCreate(ctx, str.string, str.length, &&_enter);
if (word->length == 0) {
x.nt = p4WordCreate(ctx, str.string, str.length, &&_enter);
p4AllocStack(ctx, &ctx->ds, 1+(x.nt->length == 0));
if (x.nt->length == 0) {
/* :NONAME leaves xt on stack. */
P4_PUSH(ctx->ds, word);
P4_PUSH(ctx->ds, x.nt);
}
/* Save sentinel for control imbalance test below. */
P4_PUSH(ctx->ds, (P4_Uint) P4_MARKER);
/* Keep new word hidden while compiling. */
P4_WORD_SET_HIDDEN(word);
P4_WORD_SET_HIDDEN(x.nt);
NEXT;

// (C: colon -- ) (R: ip -- )
Expand Down Expand Up @@ -1671,25 +1671,25 @@ _eval_file: P4_DROP(ctx->ds, 1);
*/
// ( <spaces>name -- )
_create: str = p4ParseName(ctx->input);
word = p4WordCreate(ctx, str.string, str.length, &&_data_field);
x.nt = p4WordCreate(ctx, str.string, str.length, &&_data_field);
// Reserve the 1st data cell for possible DOES>; wasted otherwise.
p4WordAppend(ctx, (P4_Cell)(P4_Int) 0),
P4_WORD_SET(word, P4_BIT_CREATED);
P4_WORD_SET(x.nt, P4_BIT_CREATED);
NEXT;

// ( caddr u -- )
_created: P4_DROP(ctx->ds, 1);
w = P4_POP(ctx->ds);
word = p4WordCreate(ctx, w.s, x.z, &&_nop);
P4_WORD_SET(word, P4_BIT_CREATED);
x.nt = p4WordCreate(ctx, w.s, x.z, &&_nop);
P4_WORD_SET(x.nt, P4_BIT_CREATED);
NEXT;

// DOES>
_does: word = *ctx->active;
if (!P4_WORD_IS(word, P4_BIT_CREATED)) {
_does: w.nt = *ctx->active;
if (!P4_WORD_IS(w.nt, P4_BIT_CREATED)) {
THROW(P4_THROW_NOT_CREATED);
}
word->code = &&_do_does;
w.nt->code = &&_do_does;
/*** If we change (again) how a P4_Word and data are
*** stored in memory, then most likely need to fix
*** this and _seext.
Expand All @@ -1702,7 +1702,7 @@ _does: word = *ctx->active;
//
// : word CREATE ( store data) DOES> ( words) ;
// ^--- IP
word->data[0].p = ip;
w.nt->data[0].p = ip;
goto _exit;

// ( -- aaddr)
Expand Down Expand Up @@ -1739,10 +1739,10 @@ _allot: P4_DROP(ctx->ds, 1);
// ( xt <spaces>name -- )
_alias: P4_DROP(ctx->ds, 1);
str = p4ParseName(ctx->input);
word = p4WordCreate(ctx, str.string, str.length, x.nt->code);
word->ndata = x.nt->ndata;
word->data = x.nt->data;
word->bits = x.nt->bits;
w.nt = p4WordCreate(ctx, str.string, str.length, x.nt->code);
w.nt->ndata = x.nt->ndata;
w.nt->data = x.nt->data;
w.nt->bits = x.nt->bits;
NEXT;

// ( key k -- value v )
Expand Down

0 comments on commit 0a26e74

Please sign in to comment.