Program: 43958
Project: 43958
Buggy source:
/** 
 * execute instructions up to a yield, return, or call 
 */
public void exec(){
  if (cc < 0)   return;
  int i, a, b, c, o, n, cb;
  LValue rkb, rkc, nvarargs, key, val;
  LValue i0, step, idx, limit, init, table;
  boolean back, body;
  LPrototype proto;
  LClosure newClosure;
  CallInfo ci=calls[cc];
  LClosure cl=ci.closure;
  LPrototype p=cl.p;
  int[] code=p.code;
  LValue[] k=p.k;
  this.base=ci.base;
  while (true) {
    debugAssert(ci == calls[cc]);
    ci.top=top;
    if (hooksenabled) {
      debugBytecodeHooks(ci.pc);
    }
    i=code[ci.pc++];
    o=(i >> POS_OP) & MAX_OP;
    a=(i >> POS_A) & MAXARG_A;
switch (o) {
case LuaState.OP_MOVE:
{
        b=LuaState.GETARG_B(i);
        this.stack[base + a]=this.stack[base + b];
        continue;
      }
case LuaState.OP_LOADK:
{
      b=LuaState.GETARG_Bx(i);
      this.stack[base + a]=k[b];
      continue;
    }
case LuaState.OP_LOADBOOL:
{
    b=LuaState.GETARG_B(i);
    c=LuaState.GETARG_C(i);
    this.stack[base + a]=(b != 0 ? LBoolean.TRUE : LBoolean.FALSE);
    if (c != 0)     ci.pc++;
    continue;
  }
case LuaState.OP_LOADNIL:
{
  b=LuaState.GETARG_B(i);
  do {
    this.stack[base + b]=LNil.NIL;
  }
 while ((--b) >= a);
  continue;
}
case LuaState.OP_GETUPVAL:
{
b=LuaState.GETARG_B(i);
this.stack[base + a]=cl.upVals[b].getValue();
continue;
}
case LuaState.OP_GETGLOBAL:
{
b=LuaState.GETARG_Bx(i);
key=k[b];
table=cl.env;
val=this.luaV_gettable(table,key);
this.stack[base + a]=val;
continue;
}
case LuaState.OP_GETTABLE:
{
b=LuaState.GETARG_B(i);
key=GETARG_RKC(k,i);
table=this.stack[base + b];
val=this.luaV_gettable(table,key);
this.stack[base + a]=val;
continue;
}
case LuaState.OP_SETGLOBAL:
{
b=LuaState.GETARG_Bx(i);
key=k[b];
val=this.stack[base + a];
table=cl.env;
this.luaV_settable(table,key,val);
continue;
}
case LuaState.OP_SETUPVAL:
{
b=LuaState.GETARG_B(i);
cl.upVals[b].setValue(this.stack[base + a]);
continue;
}
case LuaState.OP_SETTABLE:
{
key=GETARG_RKB(k,i);
val=GETARG_RKC(k,i);
table=this.stack[base + a];
this.luaV_settable(table,key,val);
continue;
}
case LuaState.OP_NEWTABLE:
{
b=LuaState.GETARG_B(i);
c=LuaState.GETARG_C(i);
this.stack[base + a]=new LTable(b,c);
continue;
}
case LuaState.OP_SELF:
{
rkb=GETARG_RKB(k,i);
rkc=GETARG_RKC(k,i);
val=this.luaV_gettable(rkb,rkc);
this.stack[base + a]=val;
this.stack[base + a + 1]=rkb;
continue;
}
case LuaState.OP_ADD:
case LuaState.OP_SUB:
case LuaState.OP_MUL:
case LuaState.OP_DIV:
case LuaState.OP_MOD:
case LuaState.OP_POW:
{
rkb=GETARG_RKB(k,i);
rkc=GETARG_RKC(k,i);
this.stack[base + a]=rkc.luaBinOpUnknown(o,rkb);
continue;
}
case LuaState.OP_UNM:
{
rkb=GETARG_RKB(k,i);
this.stack[base + a]=rkb.luaUnaryMinus();
continue;
}
case LuaState.OP_NOT:
{
rkb=GETARG_RKB(k,i);
this.stack[base + a]=(!rkb.toJavaBoolean() ? LBoolean.TRUE : LBoolean.FALSE);
continue;
}
case LuaState.OP_LEN:
{
rkb=GETARG_RKB(k,i);
this.stack[base + a]=LInteger.valueOf(rkb.luaLength());
continue;
}
case LuaState.OP_CONCAT:
{
b=LuaState.GETARG_B(i);
c=LuaState.GETARG_C(i);
int numValues=c - b + 1;
ByteArrayOutputStream baos=new ByteArrayOutputStream();
for (int j=b, l=0; j <= c; j++, l++) {
this.stack[base + j].luaConcatTo(baos);
}
this.stack[base + a]=new LString(baos.toByteArray());
continue;
}
case LuaState.OP_JMP:
{
ci.pc+=LuaState.GETARG_sBx(i);
continue;
}
case LuaState.OP_EQ:
case LuaState.OP_LT:
case LuaState.OP_LE:
{
rkb=GETARG_RKB(k,i);
rkc=GETARG_RKC(k,i);
boolean test=rkc.luaBinCmpUnknown(o,rkb);
if (test == (a == 0)) ci.pc++;
continue;
}
case LuaState.OP_TEST:
{
c=LuaState.GETARG_C(i);
if (this.stack[base + a].toJavaBoolean() != (c != 0)) ci.pc++;
continue;
}
case LuaState.OP_TESTSET:
{
rkb=GETARG_RKB(k,i);
c=LuaState.GETARG_C(i);
if (rkb.toJavaBoolean() != (c != 0)) ci.pc++;
 else this.stack[base + a]=rkb;
continue;
}
case LuaState.OP_CALL:
{
this.base+=a;
b=LuaState.GETARG_B(i);
if (b != 0) luaV_settop_fillabove(base + b);
c=LuaState.GETARG_C(i);
if (hooksenabled) {
debugCallHooks(ci.pc - 1);
}
this.nresults=c - 1;
if (this.stack[base].luaStackCall(this)) return;
if (c > 0) luaV_adjusttop(base + c - 1);
base=ci.base;
continue;
}
case LuaState.OP_TAILCALL:
{
if (hooksenabled) {
debugTailReturnHooks(ci.pc - 1);
}
closeUpVals(base);
b=LuaState.GETARG_B(i);
if (b != 0) luaV_settop_fillabove(base + a + b);
 else b=top - (base + a);
System.arraycopy(stack,base + a,stack,ci.resultbase,b);
this.base=ci.resultbase;
luaV_settop_fillabove(base + b);
this.nresults=ci.nresults;
--cc;
try {
if (this.stack[base].luaStackCall(this)) {
return;
}
}
 catch (LuaErrorException e) {
cc++;
throw e;
}
if (ci.nresults >= 0) luaV_adjusttop(base + ci.nresults);
return;
}
case LuaState.OP_RETURN:
{
if (hooksenabled) {
debugReturnHooks(ci.pc - 1);
}
closeUpVals(base);
b=LuaState.GETARG_B(i) - 1;
if (b >= 0) luaV_settop_fillabove(base + a + b);
 else b=top - (base + a);
System.arraycopy(stack,base + a,stack,ci.resultbase,b);
debugAssert(ci.resultbase + b <= top);
luaV_settop_fillabove(ci.resultbase + b);
if (ci.nresults >= 0) luaV_adjusttop(ci.resultbase + ci.nresults);
calls[cc--]=null;
return;
}
case LuaState.OP_FORLOOP:
{
i0=this.stack[base + a];
step=this.stack[base + a + 2];
idx=step.luaBinOpUnknown(Lua.OP_ADD,i0);
limit=this.stack[base + a + 1];
back=step.luaBinCmpInteger(Lua.OP_LT,0);
body=(back ? idx.luaBinCmpUnknown(Lua.OP_LE,limit) : limit.luaBinCmpUnknown(Lua.OP_LE,idx));
if (body) {
this.stack[base + a]=idx;
this.stack[base + a + 3]=idx;
ci.pc+=LuaState.GETARG_sBx(i);
}
continue;
}
case LuaState.OP_FORPREP:
{
init=this.stack[base + a].luaToNumber();
limit=this.stack[base + a + 1].luaToNumber();
step=this.stack[base + a + 2].luaToNumber();
if (init.isNil()) error("String_Node_Str");
if (limit.isNil()) error("String_Node_Str");
if (step.isNil()) error("String_Node_Str");
this.stack[base + a]=step.luaBinOpUnknown(Lua.OP_SUB,init);
this.stack[base + a + 1]=limit;
this.stack[base + a + 2]=step;
b=LuaState.GETARG_sBx(i);
ci.pc+=b;
continue;
}
case LuaState.OP_TFORLOOP:
{
cb=base + a + 3;
base=cb;
System.arraycopy(this.stack,cb - 3,this.stack,cb,3);
luaV_settop_fillabove(cb + 3);
c=LuaState.GETARG_C(i);
this.nresults=c;
if (this.stack[cb].luaStackCall(this)) execute();
base=ci.base;
luaV_adjusttop(cb + c);
if (!this.stack[cb].isNil()) {
this.stack[cb - 1]=this.stack[cb];
}
 else {
ci.pc++;
}
continue;
}
case LuaState.OP_SETLIST:
{
b=LuaState.GETARG_B(i);
c=LuaState.GETARG_C(i);
int listBase=base + a;
if (b == 0) {
b=top - listBase - 1;
}
if (c == 0) {
c=code[ci.pc++];
}
int offset=(c - 1) * LFIELDS_PER_FLUSH;
LTable tbl=(LTable)this.stack[base + a];
tbl.arrayPresize(offset + b);
for (int j=1; j <= b; j++) {
tbl.put(offset + j,stack[listBase + j]);
}
continue;
}
case LuaState.OP_CLOSE:
{
closeUpVals(base + a);
continue;
}
case LuaState.OP_CLOSURE:
{
b=LuaState.GETARG_Bx(i);
proto=cl.p.p[b];
newClosure=proto.newClosure(cl.env);
for (int j=0; j < newClosure.upVals.length; j++, ci.pc++) {
i=code[ci.pc];
o=LuaState.GET_OPCODE(i);
b=LuaState.GETARG_B(i);
if (o == LuaState.OP_GETUPVAL) {
newClosure.upVals[j]=cl.upVals[b];
}
 else if (o == LuaState.OP_MOVE) {
newClosure.upVals[j]=findUpVal(base + b);
}
 else {
throw new java.lang.IllegalArgumentException("String_Node_Str" + o);
}
}
this.stack[base + a]=newClosure;
continue;
}
case LuaState.OP_VARARG:
{
b=LuaState.GETARG_B(i) - 1;
nvarargs=this.stack[base - 1];
n=nvarargs.toJavaInt();
if (b == LuaState.LUA_MULTRET) {
b=n;
}
checkstack(a + b);
for (int j=0; j < b; j++) this.stack[base + a + j]=(j < n ? this.stack[base - n + j - 1] : LNil.NIL);
luaV_settop_fillabove(base + a + b);
continue;
}
}
}
}

Fixed version (ground truth):
/** 
 * execute instructions up to a yield, return, or call 
 */
public void exec(){
  if (cc < 0)   return;
  int i, a, b, c, o, n, cb;
  LValue rkb, rkc, nvarargs, key, val;
  LValue i0, step, idx, limit, init, table;
  boolean back, body;
  LPrototype proto;
  LClosure newClosure;
  CallInfo ci=calls[cc];
  LClosure cl=ci.closure;
  LPrototype p=cl.p;
  int[] code=p.code;
  LValue[] k=p.k;
  this.base=ci.base;
  while (true) {
    debugAssert(ci == calls[cc]);
    ci.top=top;
    if (hooksenabled) {
      debugBytecodeHooks(ci.pc);
    }
    i=code[ci.pc++];
    o=(i >> POS_OP) & MAX_OP;
    a=(i >> POS_A) & MAXARG_A;
switch (o) {
case LuaState.OP_MOVE:
{
        b=LuaState.GETARG_B(i);
        this.stack[base + a]=this.stack[base + b];
        continue;
      }
case LuaState.OP_LOADK:
{
      b=LuaState.GETARG_Bx(i);
      this.stack[base + a]=k[b];
      continue;
    }
case LuaState.OP_LOADBOOL:
{
    b=LuaState.GETARG_B(i);
    c=LuaState.GETARG_C(i);
    this.stack[base + a]=(b != 0 ? LBoolean.TRUE : LBoolean.FALSE);
    if (c != 0)     ci.pc++;
    continue;
  }
case LuaState.OP_LOADNIL:
{
  b=LuaState.GETARG_B(i);
  do {
    this.stack[base + b]=LNil.NIL;
  }
 while ((--b) >= a);
  continue;
}
case LuaState.OP_GETUPVAL:
{
b=LuaState.GETARG_B(i);
this.stack[base + a]=cl.upVals[b].getValue();
continue;
}
case LuaState.OP_GETGLOBAL:
{
b=LuaState.GETARG_Bx(i);
key=k[b];
table=cl.env;
val=this.luaV_gettable(table,key);
this.stack[base + a]=val;
continue;
}
case LuaState.OP_GETTABLE:
{
b=LuaState.GETARG_B(i);
key=GETARG_RKC(k,i);
table=this.stack[base + b];
val=this.luaV_gettable(table,key);
this.stack[base + a]=val;
continue;
}
case LuaState.OP_SETGLOBAL:
{
b=LuaState.GETARG_Bx(i);
key=k[b];
val=this.stack[base + a];
table=cl.env;
this.luaV_settable(table,key,val);
continue;
}
case LuaState.OP_SETUPVAL:
{
b=LuaState.GETARG_B(i);
cl.upVals[b].setValue(this.stack[base + a]);
continue;
}
case LuaState.OP_SETTABLE:
{
key=GETARG_RKB(k,i);
val=GETARG_RKC(k,i);
table=this.stack[base + a];
this.luaV_settable(table,key,val);
continue;
}
case LuaState.OP_NEWTABLE:
{
b=LuaState.GETARG_B(i);
c=LuaState.GETARG_C(i);
this.stack[base + a]=new LTable(b,c);
continue;
}
case LuaState.OP_SELF:
{
rkb=GETARG_RKB(k,i);
rkc=GETARG_RKC(k,i);
val=this.luaV_gettable(rkb,rkc);
this.stack[base + a]=val;
this.stack[base + a + 1]=rkb;
continue;
}
case LuaState.OP_ADD:
case LuaState.OP_SUB:
case LuaState.OP_MUL:
case LuaState.OP_DIV:
case LuaState.OP_MOD:
case LuaState.OP_POW:
{
rkb=GETARG_RKB(k,i);
rkc=GETARG_RKC(k,i);
this.stack[base + a]=rkc.luaBinOpUnknown(o,rkb);
continue;
}
case LuaState.OP_UNM:
{
rkb=GETARG_RKB(k,i);
this.stack[base + a]=rkb.luaUnaryMinus();
continue;
}
case LuaState.OP_NOT:
{
rkb=GETARG_RKB(k,i);
this.stack[base + a]=(!rkb.toJavaBoolean() ? LBoolean.TRUE : LBoolean.FALSE);
continue;
}
case LuaState.OP_LEN:
{
rkb=GETARG_RKB(k,i);
this.stack[base + a]=LInteger.valueOf(rkb.luaLength());
continue;
}
case LuaState.OP_CONCAT:
{
b=LuaState.GETARG_B(i);
c=LuaState.GETARG_C(i);
int numValues=c - b + 1;
ByteArrayOutputStream baos=new ByteArrayOutputStream();
for (int j=b, l=0; j <= c; j++, l++) {
this.stack[base + j].luaConcatTo(baos);
}
this.stack[base + a]=new LString(baos.toByteArray());
continue;
}
case LuaState.OP_JMP:
{
ci.pc+=LuaState.GETARG_sBx(i);
continue;
}
case LuaState.OP_EQ:
case LuaState.OP_LT:
case LuaState.OP_LE:
{
rkb=GETARG_RKB(k,i);
rkc=GETARG_RKC(k,i);
boolean test=rkc.luaBinCmpUnknown(o,rkb);
if (test == (a == 0)) ci.pc++;
continue;
}
case LuaState.OP_TEST:
{
c=LuaState.GETARG_C(i);
if (this.stack[base + a].toJavaBoolean() != (c != 0)) ci.pc++;
continue;
}
case LuaState.OP_TESTSET:
{
rkb=GETARG_RKB(k,i);
c=LuaState.GETARG_C(i);
if (rkb.toJavaBoolean() != (c != 0)) ci.pc++;
 else this.stack[base + a]=rkb;
continue;
}
case LuaState.OP_CALL:
{
this.base+=a;
b=LuaState.GETARG_B(i);
if (b != 0) luaV_settop_fillabove(base + b);
c=LuaState.GETARG_C(i);
if (hooksenabled) {
debugCallHooks();
}
this.nresults=c - 1;
if (this.stack[base].luaStackCall(this)) return;
if (c > 0) luaV_adjusttop(base + c - 1);
base=ci.base;
continue;
}
case LuaState.OP_TAILCALL:
{
if (hooksenabled) {
debugTailReturnHooks();
}
closeUpVals(base);
b=LuaState.GETARG_B(i);
if (b != 0) luaV_settop_fillabove(base + a + b);
 else b=top - (base + a);
System.arraycopy(stack,base + a,stack,ci.resultbase,b);
this.base=ci.resultbase;
luaV_settop_fillabove(base + b);
this.nresults=ci.nresults;
--cc;
try {
if (this.stack[base].luaStackCall(this)) {
return;
}
}
 catch (LuaErrorException e) {
cc++;
throw e;
}
if (ci.nresults >= 0) luaV_adjusttop(base + ci.nresults);
return;
}
case LuaState.OP_RETURN:
{
if (hooksenabled) {
debugReturnHooks();
}
closeUpVals(base);
b=LuaState.GETARG_B(i) - 1;
if (b >= 0) luaV_settop_fillabove(base + a + b);
 else b=top - (base + a);
System.arraycopy(stack,base + a,stack,ci.resultbase,b);
debugAssert(ci.resultbase + b <= top);
luaV_settop_fillabove(ci.resultbase + b);
if (ci.nresults >= 0) luaV_adjusttop(ci.resultbase + ci.nresults);
calls[cc--]=null;
return;
}
case LuaState.OP_FORLOOP:
{
i0=this.stack[base + a];
step=this.stack[base + a + 2];
idx=step.luaBinOpUnknown(Lua.OP_ADD,i0);
limit=this.stack[base + a + 1];
back=step.luaBinCmpInteger(Lua.OP_LT,0);
body=(back ? idx.luaBinCmpUnknown(Lua.OP_LE,limit) : limit.luaBinCmpUnknown(Lua.OP_LE,idx));
if (body) {
this.stack[base + a]=idx;
this.stack[base + a + 3]=idx;
ci.pc+=LuaState.GETARG_sBx(i);
}
continue;
}
case LuaState.OP_FORPREP:
{
init=this.stack[base + a].luaToNumber();
limit=this.stack[base + a + 1].luaToNumber();
step=this.stack[base + a + 2].luaToNumber();
if (init.isNil()) error("String_Node_Str");
if (limit.isNil()) error("String_Node_Str");
if (step.isNil()) error("String_Node_Str");
this.stack[base + a]=step.luaBinOpUnknown(Lua.OP_SUB,init);
this.stack[base + a + 1]=limit;
this.stack[base + a + 2]=step;
b=LuaState.GETARG_sBx(i);
ci.pc+=b;
continue;
}
case LuaState.OP_TFORLOOP:
{
cb=base + a + 3;
base=cb;
System.arraycopy(this.stack,cb - 3,this.stack,cb,3);
luaV_settop_fillabove(cb + 3);
c=LuaState.GETARG_C(i);
this.nresults=c;
if (this.stack[cb].luaStackCall(this)) execute();
base=ci.base;
luaV_adjusttop(cb + c);
if (!this.stack[cb].isNil()) {
this.stack[cb - 1]=this.stack[cb];
}
 else {
ci.pc++;
}
continue;
}
case LuaState.OP_SETLIST:
{
b=LuaState.GETARG_B(i);
c=LuaState.GETARG_C(i);
int listBase=base + a;
if (b == 0) {
b=top - listBase - 1;
}
if (c == 0) {
c=code[ci.pc++];
}
int offset=(c - 1) * LFIELDS_PER_FLUSH;
LTable tbl=(LTable)this.stack[base + a];
tbl.arrayPresize(offset + b);
for (int j=1; j <= b; j++) {
tbl.put(offset + j,stack[listBase + j]);
}
continue;
}
case LuaState.OP_CLOSE:
{
closeUpVals(base + a);
continue;
}
case LuaState.OP_CLOSURE:
{
b=LuaState.GETARG_Bx(i);
proto=cl.p.p[b];
newClosure=proto.newClosure(cl.env);
for (int j=0; j < newClosure.upVals.length; j++, ci.pc++) {
i=code[ci.pc];
o=LuaState.GET_OPCODE(i);
b=LuaState.GETARG_B(i);
if (o == LuaState.OP_GETUPVAL) {
newClosure.upVals[j]=cl.upVals[b];
}
 else if (o == LuaState.OP_MOVE) {
newClosure.upVals[j]=findUpVal(base + b);
}
 else {
throw new java.lang.IllegalArgumentException("String_Node_Str" + o);
}
}
this.stack[base + a]=newClosure;
continue;
}
case LuaState.OP_VARARG:
{
b=LuaState.GETARG_B(i) - 1;
nvarargs=this.stack[base - 1];
n=nvarargs.toJavaInt();
if (b == LuaState.LUA_MULTRET) {
b=n;
}
checkstack(a + b);
for (int j=0; j < b; j++) this.stack[base + a + j]=(j < n ? this.stack[base - n + j - 1] : LNil.NIL);
luaV_settop_fillabove(base + a + b);
continue;
}
}
}
}