fix nc -do ""
[nedit-bw.git] / jump-target-check.patch
blob2fa692010cf9cff87b8de45a101f8cf7e0bf05b9
1 ---
3 source/interpret.c | 13 ++++++++-----
4 source/interpret.h | 1 +
5 2 files changed, 9 insertions(+), 5 deletions(-)
7 diff --quilt old/source/interpret.c new/source/interpret.c
8 --- old/source/interpret.c
9 +++ new/source/interpret.c
10 @@ -292,17 +292,16 @@ AccumulatorData *BeginCreatingProgram(co
11 Program *FinishCreatingProgram(AccumulatorData *old)
13 Program *newProg;
14 - int progLen;
16 newProg = XtNew(Program);
17 newProg->name = LookupString(ProgramName, True);
18 - progLen = ProgP - Prog;
19 - newProg->code = (Inst *)XtCalloc(progLen, sizeof(Inst));
20 - memcpy(newProg->code, Prog, progLen * sizeof(Inst));
21 + newProg->progLen = ProgP - Prog;
22 + newProg->code = (Inst *)XtCalloc(newProg->progLen, sizeof(Inst));
23 + memcpy(newProg->code, Prog, newProg->progLen * sizeof(Inst));
24 newProg->nested = False;
25 newProg->refcount = 0;
27 - DISASM(newProg->name, newProg->code, ProgP - Prog);
28 + DISASM(newProg->name, newProg->code, newProg->progLen);
30 XtFree((char *)Accumulator);
31 Accumulator = old;
32 @@ -1265,6 +1264,10 @@ static void addToGlobalSymTab(Symbol *sy
34 #define JUMP(a) \
35 do { \
36 + Program *prog = FP_GET_PROG(FrameP); \
37 + if (!(prog->code <= (a) && (a) < (prog->code + prog->progLen))) { \
38 + EXEC_ERROR("Branch target outside current frame", NULL); \
39 + } \
40 PC = (a); \
41 } while (0)
43 diff --quilt old/source/interpret.h new/source/interpret.h
44 --- old/source/interpret.h
45 +++ new/source/interpret.h
46 @@ -122,6 +122,7 @@ typedef struct SymbolRec {
48 typedef struct ProgramTag {
49 const char *name;
50 + unsigned progLen;
51 Inst *code;
52 unsigned nested:1;
53 unsigned refcount:31;