Program: 143937
Project: 143937
Buggy source:
/** 
 * parse the input buffer
 * @param b      input buffer byte array
 * @param length count of valid bytes in buffer
 * @return       new length of valid bytes in buffer
 */
protected int parse(byte[] b,int length) throws IOException {
  int index, resindex;
  for (index=resindex=0; index < length; index++) {
switch (state) {
case 0:
      if ((char)b[index] == '@') {
        cmd[cmdlen++]=b[index];
        state=1;
      }
 else {
        res[resindex++]=b[index];
      }
    break;
case 1:
  if ((char)b[index] == '@') {
    for (int i=0; i < cmdlen; i++)     res[resindex++]=cmd[i];
    cmdlen=0;
    cmd[cmdlen++]=b[index];
  }
 else {
    cmd[cmdlen++]=b[index];
    if (cmdlen == 4) {
      if (equals(cmd,RFS)) {
        visual.refreshScene();
        reset();
      }
 else       if (equals(cmd,RQV)) {
        write("String_Node_Str" + VERSION + "String_Node_Str");
        reset();
      }
 else       if (equals(cmd,SCE)) {
        state=2;
      }
 else       if (equals(cmd,VIO)) {
        state=2;
      }
 else       if (equals(cmd,DFO)) {
        state=2;
      }
 else       if (equals(cmd,RMO)) {
        state=2;
      }
 else       if (equals(cmd,DFS)) {
        state=2;
      }
 else       if (equals(cmd,TMS)) {
        byte[] temp="String_Node_Str".getBytes();
        for (int i=0; i < temp.length; i++)         res[resindex++]=temp[i];
        reset();
      }
 else {
        for (int i=0; i < cmdlen; i++)         res[resindex++]=cmd[i];
        reset();
      }
    }
  }
break;
case 2:
if ((char)b[index] == '@') {
for (int i=0; i < cmdlen; i++) res[resindex++]=cmd[i];
for (int i=0; i < idlen; i++) res[resindex++]=id[i];
cmdlen=0;
cmd[cmdlen++]=b[index];
idlen=0;
state=1;
}
 else if ((char)b[index] != '.') {
id[idlen++]=b[index];
}
 else {
obj=new String(id,0,idlen);
if (equals(cmd,SCE)) {
  String query=visual.showScene(obj);
  if (query != null)   write(query);
  reset();
}
 else if (equals(cmd,VIO)) {
  state=6;
}
 else if (equals(cmd,RMO)) {
  visual.removeObject(obj);
  reset();
}
 else if (equals(cmd,DFS)) {
  state=3;
}
 else if (equals(cmd,DFO)) {
  state=3;
}
}
break;
case 3:
hex[hexlen++]=b[index];
if (hexlen == 2) {
polys=hexToInt(hex);
if (polys > 32 || polys < 0) {
DBG("String_Node_Str" + polys + "String_Node_Str"+ obj);
if (ignoreErrors) {
DBG("String_Node_Str");
cmdlen=0;
state=8;
}
 else {
reset();
}
}
 else {
data=new int[polys][];
state=4;
hexlen=0;
}
}
break;
case 4:
hex[hexlen++]=b[index];
if (hexlen == 2) {
edges=hexToInt(hex);
if (edges > 32 || edges < 0) {
DBG("String_Node_Str" + edges + "String_Node_Str"+ obj);
if (ignoreErrors) {
DBG("String_Node_Str");
cmdlen=0;
state=8;
}
 else {
reset();
}
}
 else {
data[poly]=new int[1 + edges * 2];
state=5;
hexlen=0;
}
}
break;
case 5:
hex[hexlen++]=b[index];
if (hexlen == 2) {
int c=hexToInt(hex);
if (c < 0) {
DBG("String_Node_Str" + c + "String_Node_Str"+ obj);
if (ignoreErrors) {
DBG("String_Node_Str");
cmdlen=0;
state=8;
}
 else {
reset();
}
}
 else {
data[poly][pos]=c;
hexlen=0;
pos++;
if (pos == edges * 2 + 1) {
poly++;
state=4;
pos=0;
if (poly == polys) {
if (equals(cmd,DFS)) {
visual.defineScene(obj,data);
}
 else if (equals(cmd,DFO)) {
visual.defineObject(obj,data);
}
reset();
}
}
}
}
break;
case 6:
hex[hexlen++]=b[index];
if (hexlen == 2) {
xpos=hexToInt(hex);
if (xpos > 15 || xpos < 0) {
DBG("String_Node_Str" + xpos + "String_Node_Str"+ obj);
reset();
}
 else {
state=7;
hexlen=0;
}
}
break;
case 7:
hex[hexlen++]=b[index];
if (hexlen == 2) {
ypos=hexToInt(hex);
if (ypos > 7 || ypos < 0) {
DBG("String_Node_Str" + ypos + "String_Node_Str"+ obj);
reset();
}
 else {
String query=visual.showObject(obj,xpos,ypos);
if (query != null) write(query);
reset();
}
}
break;
case 8:
if ((char)b[index] == '@') {
cmdlen=0;
cmd[cmdlen++]=b[index];
}
 else if (cmdlen > 0) {
cmd[cmdlen++]=b[index];
if (cmdlen == 4) {
if (equals(cmd,RFS)) {
visual.refreshScene();
reset();
}
 else {
cmdlen=0;
}
}
}
 else {
}
break;
}
}
System.arraycopy(res,0,b,0,resindex);
return resindex;
}

Fixed version (ground truth):
/** 
 * parse the input buffer
 * @param b      input buffer byte array
 * @param length count of valid bytes in buffer
 * @return       new length of valid bytes in buffer
 */
protected int parse(byte[] b,int length) throws IOException {
  int index, resindex;
  for (index=resindex=0; index < length; index++) {
switch (state) {
case 0:
      if ((char)b[index] == '@') {
        cmd[cmdlen++]=b[index];
        state=1;
      }
 else {
        res[resindex++]=b[index];
      }
    break;
case 1:
  if ((char)b[index] == '@') {
    for (int i=0; i < cmdlen; i++)     res[resindex++]=cmd[i];
    cmdlen=0;
    cmd[cmdlen++]=b[index];
  }
 else {
    cmd[cmdlen++]=b[index];
    if (cmdlen == 4) {
      if (equals(cmd,RFS)) {
        visual.refreshScene();
        reset();
      }
 else       if (equals(cmd,RQV)) {
        write("String_Node_Str" + VERSION + "String_Node_Str");
        reset();
      }
 else       if (equals(cmd,SCE)) {
        state=2;
      }
 else       if (equals(cmd,VIO)) {
        state=2;
      }
 else       if (equals(cmd,DFO)) {
        state=2;
      }
 else       if (equals(cmd,RMO)) {
        state=2;
      }
 else       if (equals(cmd,DFS)) {
        state=2;
      }
 else       if (equals(cmd,TMS)) {
        byte[] temp="String_Node_Str".getBytes();
        for (int i=0; i < temp.length; i++)         res[resindex++]=temp[i];
        reset();
      }
 else {
        for (int i=0; i < cmdlen; i++)         res[resindex++]=cmd[i];
        reset();
      }
    }
  }
break;
case 2:
if ((char)b[index] == '@') {
for (int i=0; i < cmdlen; i++) res[resindex++]=cmd[i];
for (int i=0; i < idlen; i++) res[resindex++]=id[i];
cmdlen=0;
cmd[cmdlen++]=b[index];
idlen=0;
state=1;
}
 else if ((char)b[index] != '.') {
id[idlen++]=b[index];
}
 else {
obj=new String(id,0,idlen);
if (equals(cmd,SCE)) {
  String query=visual.showScene(obj);
  if (query != null)   write(query);
  reset();
}
 else if (equals(cmd,VIO)) {
  state=6;
}
 else if (equals(cmd,RMO)) {
  visual.removeObject(obj);
  reset();
}
 else if (equals(cmd,DFS)) {
  state=3;
}
 else if (equals(cmd,DFO)) {
  state=3;
}
}
break;
case 3:
hex[hexlen++]=b[index];
if (hexlen == 2) {
polys=hexToInt(hex);
if (polys > 32 || polys < 0) {
DBG("String_Node_Str" + polys + "String_Node_Str"+ obj);
if (ignoreErrors) {
DBG("String_Node_Str");
cmdlen=0;
state=8;
}
 else {
reset();
}
}
 else {
data=new int[polys][];
if (polys > 0) {
state=4;
}
 else {
if (equals(cmd,DFS)) {
visual.defineScene(obj,data);
}
 else if (equals(cmd,DFO)) {
visual.defineObject(obj,data);
}
reset();
}
hexlen=0;
}
}
break;
case 4:
hex[hexlen++]=b[index];
if (hexlen == 2) {
edges=hexToInt(hex);
if (edges > 32 || edges < 0) {
DBG("String_Node_Str" + edges + "String_Node_Str"+ obj);
if (ignoreErrors) {
DBG("String_Node_Str");
cmdlen=0;
state=8;
}
 else {
reset();
}
}
 else {
data[poly]=new int[1 + edges * 2];
state=5;
hexlen=0;
}
}
break;
case 5:
hex[hexlen++]=b[index];
if (hexlen == 2) {
int c=hexToInt(hex);
if (c < 0) {
DBG("String_Node_Str" + c + "String_Node_Str"+ obj);
if (ignoreErrors) {
DBG("String_Node_Str");
cmdlen=0;
state=8;
}
 else {
reset();
}
}
 else {
data[poly][pos]=c;
hexlen=0;
pos++;
if (pos == edges * 2 + 1) {
poly++;
state=4;
pos=0;
if (poly == polys) {
if (equals(cmd,DFS)) {
visual.defineScene(obj,data);
}
 else if (equals(cmd,DFO)) {
visual.defineObject(obj,data);
}
reset();
}
}
}
}
break;
case 6:
hex[hexlen++]=b[index];
if (hexlen == 2) {
xpos=hexToInt(hex);
if (xpos > 15 || xpos < 0) {
DBG("String_Node_Str" + xpos + "String_Node_Str"+ obj);
reset();
}
 else {
state=7;
hexlen=0;
}
}
break;
case 7:
hex[hexlen++]=b[index];
if (hexlen == 2) {
ypos=hexToInt(hex);
if (ypos > 7 || ypos < 0) {
DBG("String_Node_Str" + ypos + "String_Node_Str"+ obj);
reset();
}
 else {
String query=visual.showObject(obj,xpos,ypos);
if (query != null) write(query);
reset();
}
}
break;
case 8:
if ((char)b[index] == '@') {
cmdlen=0;
cmd[cmdlen++]=b[index];
}
 else if (cmdlen > 0) {
cmd[cmdlen++]=b[index];
if (cmdlen == 4) {
if (equals(cmd,RFS)) {
visual.refreshScene();
reset();
}
 else {
cmdlen=0;
}
}
}
 else {
}
break;
}
}
System.arraycopy(res,0,b,0,resindex);
return resindex;
}