Program: 43986
Project: 43986
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;
    debugHooks(ci.pc);
    i=code[ci.pc++];
    a=LuaState.GETARG_A(i);
switch (LuaState.GET_OPCODE(i)) {
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;
top=base + a;
table.luaGetTable(this,table,key);
continue;
}
case LuaState.OP_GETTABLE:
{
b=LuaState.GETARG_B(i);
key=GETARG_RKC(k,i);
table=this.stack[base + b];
top=base + a;
table.luaGetTable(this,table,key);
continue;
}
case LuaState.OP_SETGLOBAL:
{
b=LuaState.GETARG_Bx(i);
key=k[b];
val=this.stack[base + a];
table=cl.env;
table.luaSetTable(this,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];
table.luaSetTable(this,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);
top=base + a;
rkb.luaGetTable(this,rkb,rkc);
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:
{
o=LuaState.GET_OPCODE(i);
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;
LString[] strings=new LString[numValues];
for (int j=b, l=0; j <= c; j++, l++) {
LString s=this.stack[base + j].luaAsString();
strings[l]=s;
}
this.stack[base + a]=LString.concat(strings);
continue;
}
case LuaState.OP_JMP:
{
ci.pc+=LuaState.GETARG_sBx(i);
continue;
}
case LuaState.OP_EQ:
case LuaState.OP_LT:
case LuaState.OP_LE:
{
o=LuaState.GET_OPCODE(i);
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) top=base + b;
c=LuaState.GETARG_C(i);
this.nresults=c - 1;
if (this.stack[base].luaStackCall(this)) return;
if (c > 0) adjustTop(base + c - 1);
base=ci.base;
continue;
}
case LuaState.OP_TAILCALL:
{
closeUpVals(base);
b=LuaState.GETARG_B(i);
if (b == 0) b=top - (base + a);
System.arraycopy(stack,base + a,stack,ci.resultbase,b);
this.base=ci.resultbase;
this.top=base + b;
this.nresults=ci.nresults;
--cc;
try {
if (this.stack[base].luaStackCall(this)) {
return;
}
}
 catch (LuaErrorException e) {
cc++;
throw e;
}
if (this.nresults >= 0) adjustTop(base + nresults);
return;
}
case LuaState.OP_RETURN:
{
b=LuaState.GETARG_B(i) - 1;
if (b == -1) b=top - (base + a);
closeUpVals(base);
System.arraycopy(stack,base + a,stack,ci.resultbase,b);
top=ci.resultbase + b;
if (ci.nresults >= 0) adjustTop(ci.resultbase + ci.nresults);
--cc;
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;
top=base + a + 3+ 1;
ci.pc+=LuaState.GETARG_sBx(i);
}
continue;
}
case LuaState.OP_FORPREP:
{
init=this.stack[base + a];
step=this.stack[base + a + 2];
this.stack[base + a]=step.luaBinOpUnknown(Lua.OP_SUB,init);
b=LuaState.GETARG_sBx(i);
ci.pc+=b;
continue;
}
case LuaState.OP_TFORLOOP:
{
cb=base + a + 3;
base=cb;
adjustTop(cb + 3);
System.arraycopy(this.stack,cb - 3,this.stack,cb,3);
c=LuaState.GETARG_C(i);
this.nresults=c;
if (this.stack[cb].luaStackCall(this)) execute();
base=ci.base;
adjustTop(cb + c);
if (this.stack[cb] != LNil.NIL) {
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];
for (int j=1; j <= b; j++) {
tbl.put(offset + j,stack[listBase + j]);
}
top=base + a - 1;
continue;
}
case LuaState.OP_CLOSE:
{
closeUpVals(a);
continue;
}
case LuaState.OP_CLOSURE:
{
b=LuaState.GETARG_Bx(i);
proto=cl.p.p[b];
newClosure=new LClosure(proto,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(proto.upvalues[j],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);
top=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;
    debugHooks(ci.pc);
    i=code[ci.pc++];
    a=LuaState.GETARG_A(i);
switch (LuaState.GET_OPCODE(i)) {
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;
top=base + a;
table.luaGetTable(this,table,key);
continue;
}
case LuaState.OP_GETTABLE:
{
b=LuaState.GETARG_B(i);
key=GETARG_RKC(k,i);
table=this.stack[base + b];
top=base + a;
table.luaGetTable(this,table,key);
continue;
}
case LuaState.OP_SETGLOBAL:
{
b=LuaState.GETARG_Bx(i);
key=k[b];
val=this.stack[base + a];
table=cl.env;
table.luaSetTable(this,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];
table.luaSetTable(this,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);
top=base + a;
rkb.luaGetTable(this,rkb,rkc);
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:
{
o=LuaState.GET_OPCODE(i);
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;
LString[] strings=new LString[numValues];
for (int j=b, l=0; j <= c; j++, l++) {
LString s=this.stack[base + j].luaAsString();
strings[l]=s;
}
this.stack[base + a]=LString.concat(strings);
continue;
}
case LuaState.OP_JMP:
{
ci.pc+=LuaState.GETARG_sBx(i);
continue;
}
case LuaState.OP_EQ:
case LuaState.OP_LT:
case LuaState.OP_LE:
{
o=LuaState.GET_OPCODE(i);
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) top=base + b;
c=LuaState.GETARG_C(i);
this.nresults=c - 1;
if (this.stack[base].luaStackCall(this)) return;
if (c > 0) adjustTop(base + c - 1);
base=ci.base;
continue;
}
case LuaState.OP_TAILCALL:
{
closeUpVals(base);
b=LuaState.GETARG_B(i);
if (b == 0) b=top - (base + a);
System.arraycopy(stack,base + a,stack,ci.resultbase,b);
this.base=ci.resultbase;
this.top=base + b;
this.nresults=ci.nresults;
--cc;
try {
if (this.stack[base].luaStackCall(this)) {
return;
}
}
 catch (LuaErrorException e) {
cc++;
throw e;
}
if (this.nresults >= 0) adjustTop(base + nresults);
return;
}
case LuaState.OP_RETURN:
{
b=LuaState.GETARG_B(i) - 1;
if (b == -1) b=top - (base + a);
closeUpVals(base);
System.arraycopy(stack,base + a,stack,ci.resultbase,b);
top=ci.resultbase + b;
if (ci.nresults >= 0) adjustTop(ci.resultbase + ci.nresults);
--cc;
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;
top=base + a + 3+ 1;
ci.pc+=LuaState.GETARG_sBx(i);
}
continue;
}
case LuaState.OP_FORPREP:
{
init=this.stack[base + a];
step=this.stack[base + a + 2];
this.stack[base + a]=step.luaBinOpUnknown(Lua.OP_SUB,init);
b=LuaState.GETARG_sBx(i);
ci.pc+=b;
continue;
}
case LuaState.OP_TFORLOOP:
{
cb=base + a + 3;
base=cb;
adjustTop(cb + 3);
System.arraycopy(this.stack,cb - 3,this.stack,cb,3);
c=LuaState.GETARG_C(i);
this.nresults=c;
if (this.stack[cb].luaStackCall(this)) execute();
base=ci.base;
adjustTop(cb + c);
if (this.stack[cb] != LNil.NIL) {
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];
for (int j=1; j <= b; j++) {
tbl.put(offset + j,stack[listBase + j]);
}
top=base + a - 1;
continue;
}
case LuaState.OP_CLOSE:
{
closeUpVals(base + a);
continue;
}
case LuaState.OP_CLOSURE:
{
b=LuaState.GETARG_Bx(i);
proto=cl.p.p[b];
newClosure=new LClosure(proto,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(proto.upvalues[j],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);
top=base + a + b;
continue;
}
}
}
}