nus-yam/ex-repair huggingface dataset:
Program: 5538
Project: 5538
Buggy source:
public int read(int address,int mode) throws EmulationException {
  int val=0;
  if (address > MAX_MEM) {
    printWarning(ADDRESS_OUT_OF_BOUNDS_READ,address);
    address%=MAX_MEM;
  }
  boolean word=mode != MODE_BYTE;
  if (address < MAX_MEM_IO) {
    val=memIn[address].read(address,word,cycles);
    if (mode == MODE_WORD20) {
      val|=memIn[address + 2].read(address,word,cycles) << 16;
    }
  }
 else {
    if (isFlashBusy && flash.addressInFlash(address)) {
      flash.notifyRead(address);
    }
    val=memory[address] & 0xff;
    if (mode > MODE_BYTE) {
      val|=(memory[address + 1] << 8);
      if ((address & 1) != 0) {
        printWarning(MISALIGNED_READ,address);
      }
      if (mode == MODE_WORD20) {
        val|=(memory[address + 2] << 16) | (memory[address + 3] << 24);
        val&=0xfffff;
      }
 else {
        val&=0xffff;
      }
    }
  }
  CPUMonitor wp=watchPoints[address];
  if (wp != null) {
    wp.cpuAction(CPUMonitor.MEMORY_READ,address,val);
  }
  wp=globalMonitor;
  if (wp != null) {
    wp.cpuAction(CPUMonitor.MEMORY_READ,address,val);
  }
  return val;
}

Fixed version (ground truth):
public int read(int address,int mode) throws EmulationException {
  int val=0;
  if (address >= MAX_MEM) {
    printWarning(ADDRESS_OUT_OF_BOUNDS_READ,address);
    address%=MAX_MEM;
  }
  boolean word=mode != MODE_BYTE;
  if (address < MAX_MEM_IO) {
    val=memIn[address].read(address,word,cycles);
    if (mode == MODE_WORD20) {
      val|=memIn[address + 2].read(address,word,cycles) << 16;
    }
  }
 else {
    if (isFlashBusy && flash.addressInFlash(address)) {
      flash.notifyRead(address);
    }
    val=memory[address] & 0xff;
    if (mode > MODE_BYTE) {
      val|=(memory[address + 1] << 8);
      if ((address & 1) != 0) {
        printWarning(MISALIGNED_READ,address);
      }
      if (mode == MODE_WORD20) {
        val|=(memory[address + 2] << 16) | (memory[address + 3] << 24);
        val&=0xfffff;
      }
 else {
        val&=0xffff;
      }
    }
  }
  CPUMonitor wp=watchPoints[address];
  if (wp != null) {
    wp.cpuAction(CPUMonitor.MEMORY_READ,address,val);
  }
  wp=globalMonitor;
  if (wp != null) {
    wp.cpuAction(CPUMonitor.MEMORY_READ,address,val);
  }
  return val;
}
Program: 5539
Project: 5539
Buggy source:
public String[] getSourceFiles(){
  return null;
}

Fixed version (ground truth):
public String[] getSourceFiles(){
  String[] sourceFilesArray=new String[lineInfo.size()];
  for (int i=0; i < lineInfo.size(); i++) {
    sourceFilesArray[i]=lineInfo.get(i).sourceFiles[0];
  }
  return sourceFilesArray;
}
Program: 5540
Project: 5540
Buggy source:
public ArrayList<Integer> getExecutableAddresses(){
  return null;
}

Fixed version (ground truth):
public ArrayList<Integer> getExecutableAddresses(){
  ArrayList<Integer> executableAddresses=new ArrayList<Integer>();
  for (  LineData data : lineInfo) {
    for (    LineEntry entry : data.lineEntries) {
      executableAddresses.add(entry.address);
    }
  }
  return executableAddresses;
}
Program: 5546
Project: 5546
Buggy source:
private void run() throws EmulationException {
  while (isRunning()) {
    if (debug) {
      if (servicedInterrupt >= 0) {
        disAsm.disassemble(reg[PC],memory,reg,servicedInterrupt);
      }
 else {
        disAsm.disassemble(reg[PC],memory,reg);
      }
    }
    if (cycles > nextOut && !debug) {
      printCPUSpeed(reg[PC]);
      nextOut=cycles + 20000007;
    }
    if (emulateOP(-1)) {
      instCtr++;
      if (execCounter != null) {
        execCounter[reg[PC]]++;
      }
      if (trace != null) {
        trace[tracePos++]=reg[PC];
        if (tracePos >= trace.length)         tracePos=0;
      }
    }
    if (cycles > nextSleep) {
      try {
        Thread.sleep(10);
      }
 catch (      Exception e) {
      }
      nextSleep=cycles + sleepRate;
    }
  }
}

Fixed version (ground truth):
private void run() throws EmulationException {
  int pc;
  while (isRunning()) {
    if (debug) {
      if (servicedInterrupt >= 0) {
        disAsm.disassemble(reg[PC],memory,reg,servicedInterrupt);
      }
 else {
        disAsm.disassemble(reg[PC],memory,reg);
      }
    }
    if (cycles > nextOut && !debug) {
      printCPUSpeed(reg[PC]);
      nextOut=cycles + 20000007;
    }
    if ((pc=emulateOP(-1)) >= 0) {
      instCtr++;
      if (execCounter != null) {
        execCounter[pc]++;
      }
      if (trace != null) {
        trace[tracePos++]=pc;
        if (tracePos >= trace.length)         tracePos=0;
      }
    }
    if (cycles > nextSleep) {
      try {
        Thread.sleep(10);
      }
 catch (      Exception e) {
      }
      nextSleep=cycles + sleepRate;
    }
  }
}
Program: 5547
Project: 5547
Buggy source:
public long stepInstructions(int count) throws EmulationException {
  if (isRunning()) {
    throw new IllegalStateException("String_Node_Str");
  }
  setRunning(true);
  while (count-- > 0 && isRunning()) {
    if (debug) {
      if (servicedInterrupt >= 0) {
        disAsm.disassemble(reg[PC],memory,reg,servicedInterrupt);
      }
 else {
        disAsm.disassemble(reg[PC],memory,reg);
      }
    }
    boolean emuOP=emulateOP(-1);
    if (emuOP) {
      if (execCounter != null) {
        execCounter[reg[PC]]++;
      }
      if (trace != null) {
        trace[tracePos++]=reg[PC];
        if (tracePos > trace.length)         tracePos=0;
      }
    }
  }
  setRunning(false);
  return cycles;
}

Fixed version (ground truth):
public long stepInstructions(int count) throws EmulationException {
  if (isRunning()) {
    throw new IllegalStateException("String_Node_Str");
  }
  setRunning(true);
  while (count-- > 0 && isRunning()) {
    int pc=emulateOP(-1);
    if (pc >= 0) {
      if (execCounter != null) {
        execCounter[pc]++;
      }
      if (trace != null) {
        trace[tracePos++]=pc;
        if (tracePos > trace.length)         tracePos=0;
      }
    }
    if (debug) {
      if (servicedInterrupt >= 0) {
        disAsm.disassemble(reg[PC],memory,reg,servicedInterrupt);
      }
 else {
        disAsm.disassemble(reg[PC],memory,reg);
      }
    }
  }
  setRunning(false);
  return cycles;
}
Program: 5550
Project: 5550
Buggy source:
private void internalReset(){
  for (int i=0, n=16; i < n; i++) {
    interruptSource[i]=null;
  }
  servicedInterruptUnit=null;
  servicedInterrupt=-1;
  interruptMax=-1;
  writeRegister(SR,0);
  cycleEventQueue.removeAll();
  vTimeEventQueue.removeAll();
  bcs.reset();
  for (  Chip chip : chips) {
    chip.notifyReset();
  }
  resetIOUnits();
  if (profiler != null) {
    profiler.resetProfile();
  }
}

Fixed version (ground truth):
private void internalReset(){
  for (int i=0, n=64; i < n; i++) {
    interruptSource[i]=null;
  }
  servicedInterruptUnit=null;
  servicedInterrupt=-1;
  interruptMax=-1;
  writeRegister(SR,0);
  cycleEventQueue.removeAll();
  vTimeEventQueue.removeAll();
  bcs.reset();
  for (  Chip chip : chips) {
    chip.notifyReset();
  }
  resetIOUnits();
  if (profiler != null) {
    profiler.resetProfile();
  }
}
Program: 5552
Project: 5552
Buggy source:
private void rejectFrame(){
  rxFIFO.restore();
  setSFD(false);
  setFIFO(rxFIFO.length() > 0);
  setState(RadioState.RX_SFD_SEARCH);
}

Fixed version (ground truth):
private void rejectFrame(){
  rxFIFO.restore();
  setSFD(false);
  setFIFO(rxFIFO.length() > 0);
  frameRejected=true;
}
Program: 5553
Project: 5553
Buggy source:
public String info(){
  updateActiveFrequency();
  return "String_Node_Str" + on + "String_Node_Str"+ chipSelect+ "String_Node_Str"+ ((status & STATUS_XOSC16M_STABLE) > 0)+ "String_Node_Str"+ ((status & STATUS_RSSI_VALID) > 0)+ "String_Node_Str"+ cca+ "String_Node_Str"+ ((registers[REG_IOCFG0] & FIFOP_POLARITY) == FIFOP_POLARITY)+ "String_Node_Str"+ fifoP+ "String_Node_Str"+ currentFIFO+ "String_Node_Str"+ currentSFD+ "String_Node_Str"+ rxFIFO.stateToString()+ "String_Node_Str"+ stateMachine+ "String_Node_Str"+ state+ "String_Node_Str"+ autoAck+ "String_Node_Str"+ addressDecode+ "String_Node_Str"+ autoCRC+ "String_Node_Str"+ Utils.hex8(memory[RAM_PANID + 1])+ Utils.hex8(memory[RAM_PANID])+ "String_Node_Str"+ Utils.hex8(memory[RAM_SHORTADDR + 1])+ Utils.hex8(memory[RAM_SHORTADDR])+ "String_Node_Str"+ getLongAddress()+ "String_Node_Str"+ activeChannel+ "String_Node_Str";
}

Fixed version (ground truth):
public String info(){
  updateActiveFrequency();
  return "String_Node_Str" + on + "String_Node_Str"+ chipSelect+ "String_Node_Str"+ ((status & STATUS_XOSC16M_STABLE) > 0)+ "String_Node_Str"+ ((status & STATUS_RSSI_VALID) > 0)+ "String_Node_Str"+ cca+ "String_Node_Str"+ ((registers[REG_IOCFG0] & FIFOP_POLARITY) == FIFOP_POLARITY)+ "String_Node_Str"+ fifoP+ "String_Node_Str"+ currentFIFO+ "String_Node_Str"+ currentSFD+ "String_Node_Str"+ rxFIFO.stateToString()+ "String_Node_Str"+ rxlen+ "String_Node_Str"+ stateMachine+ "String_Node_Str"+ state+ "String_Node_Str"+ autoAck+ "String_Node_Str"+ addressDecode+ "String_Node_Str"+ autoCRC+ "String_Node_Str"+ Utils.hex8(memory[RAM_PANID + 1])+ Utils.hex8(memory[RAM_PANID])+ "String_Node_Str"+ Utils.hex8(memory[RAM_SHORTADDR + 1])+ Utils.hex8(memory[RAM_SHORTADDR])+ "String_Node_Str"+ getLongAddress()+ "String_Node_Str"+ activeChannel+ "String_Node_Str";
}
Program: 5555
Project: 5555
Buggy source:
private boolean setState(RadioState state){
  if (DEBUG)   log("String_Node_Str" + stateMachine + "String_Node_Str"+ state);
  stateMachine=state;
  registers[REG_FSMSTATE]=state.getFSMState();
switch (stateMachine) {
case VREG_OFF:
    if (DEBUG)     log("String_Node_Str");
  flushRX();
flushTX();
status&=~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE);
reset();
setMode(MODE_POWER_OFF);
updateCCA();
break;
case POWER_DOWN:
rxFIFO.reset();
status&=~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE);
reset();
setMode(MODE_POWER_OFF);
updateCCA();
break;
case RX_CALIBRATE:
setSymbolEvent(12);
setMode(MODE_RX_ON);
break;
case RX_SFD_SEARCH:
zeroSymbols=0;
if ((status & STATUS_RSSI_VALID) == 0) {
setSymbolEvent(8);
}
updateCCA();
setMode(MODE_RX_ON);
break;
case TX_CALIBRATE:
setSymbolEvent(12 + 2);
setMode(MODE_TXRX_ON);
break;
case TX_PREAMBLE:
shrPos=0;
SHR[0]=0;
SHR[1]=0;
SHR[2]=0;
SHR[3]=0;
SHR[4]=0x7A;
shrNext();
break;
case TX_FRAME:
txfifoPos=0;
txNext();
break;
case RX_WAIT:
setSymbolEvent(8);
setMode(MODE_RX_ON);
break;
case IDLE:
status&=~STATUS_RSSI_VALID;
setMode(MODE_TXRX_OFF);
updateCCA();
break;
case TX_ACK_CALIBRATE:
status|=STATUS_TX_ACTIVE;
setSymbolEvent(12 + 2 + 2);
setMode(MODE_TXRX_ON);
break;
case TX_ACK_PREAMBLE:
shrPos=0;
SHR[0]=0;
SHR[1]=0;
SHR[2]=0;
SHR[3]=0;
SHR[4]=0x7A;
shrNext();
break;
case TX_ACK:
ackPos=0;
ackNext();
break;
case RX_FRAME:
rxFIFO.mark();
rxread=0;
break;
}
if (stateListener != null) {
stateListener.newState(stateMachine);
}
stateChanged(stateMachine.state);
return true;
}

Fixed version (ground truth):
private boolean setState(RadioState state){
  if (DEBUG)   log("String_Node_Str" + stateMachine + "String_Node_Str"+ state);
  stateMachine=state;
  registers[REG_FSMSTATE]=state.getFSMState();
switch (stateMachine) {
case VREG_OFF:
    if (DEBUG)     log("String_Node_Str");
  flushRX();
flushTX();
status&=~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE);
reset();
setMode(MODE_POWER_OFF);
updateCCA();
break;
case POWER_DOWN:
rxFIFO.reset();
status&=~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE);
reset();
setMode(MODE_POWER_OFF);
updateCCA();
break;
case RX_CALIBRATE:
setSymbolEvent(12);
setMode(MODE_RX_ON);
break;
case RX_SFD_SEARCH:
zeroSymbols=0;
if ((status & STATUS_RSSI_VALID) == 0) {
setSymbolEvent(8);
}
updateCCA();
setMode(MODE_RX_ON);
break;
case TX_CALIBRATE:
setSymbolEvent(12 + 2);
setMode(MODE_TXRX_ON);
break;
case TX_PREAMBLE:
shrPos=0;
SHR[0]=0;
SHR[1]=0;
SHR[2]=0;
SHR[3]=0;
SHR[4]=0x7A;
shrNext();
break;
case TX_FRAME:
txfifoPos=0;
txNext();
break;
case RX_WAIT:
setSymbolEvent(8);
setMode(MODE_RX_ON);
break;
case IDLE:
status&=~STATUS_RSSI_VALID;
setMode(MODE_TXRX_OFF);
updateCCA();
break;
case TX_ACK_CALIBRATE:
status|=STATUS_TX_ACTIVE;
setSymbolEvent(12 + 2 + 2);
setMode(MODE_TXRX_ON);
break;
case TX_ACK_PREAMBLE:
shrPos=0;
SHR[0]=0;
SHR[1]=0;
SHR[2]=0;
SHR[3]=0;
SHR[4]=0x7A;
shrNext();
break;
case TX_ACK:
ackPos=0;
ackNext();
break;
case RX_FRAME:
rxFIFO.mark();
rxread=0;
frameRejected=false;
break;
}
if (stateListener != null) {
stateListener.newState(stateMachine);
}
stateChanged(stateMachine.state);
return true;
}
Program: 5556
Project: 5556
Buggy source:
private void triggerAccessViolation(String reason){
  if (DEBUG)   log("String_Node_Str" + reason + "String_Node_Str"+ Utils.hex16(cpu.readRegister(MSP430.PC)));
  statusreg|=ACCVIFG;
  if (sfr.isIEBitsSet(SFR.IE1,ACCVIE)) {
    cpu.flagInterrupt(NMI_VECTOR,this,true);
  }
}

Fixed version (ground truth):
private void triggerAccessViolation(String reason){
  if (DEBUG)   log("String_Node_Str" + reason + "String_Node_Str"+ Utils.hex16(cpu.readRegister(MSP430.PC)));
  statusreg|=ACCVIFG;
  if (cpu.getSFR().isIEBitsSet(SFR.IE1,ACCVIE)) {
    cpu.flagInterrupt(NMI_VECTOR,this,true);
  }
}
Program: 5557
Project: 5557
Buggy source:
public Flash(MSP430Core cpu,int[] memory,FlashRange main_range,FlashRange info_range){
  super("String_Node_Str","String_Node_Str",memory,FCTL1);
  this.cpu=cpu;
  this.memory=memory;
  this.main_range=main_range;
  this.info_range=info_range;
  this.sfr=cpu.getSFR();
  locked=true;
  reset(MSP430.RESET_POR);
}

Fixed version (ground truth):
public Flash(MSP430Core cpu,int[] memory,FlashRange main_range,FlashRange info_range){
  super("String_Node_Str","String_Node_Str",memory,FCTL1);
  this.cpu=cpu;
  this.memory=memory;
  this.main_range=main_range;
  this.info_range=info_range;
  locked=true;
  reset(MSP430.RESET_POR);
}
Program: 5558
Project: 5558
Buggy source:
void resetCounter(long cycles){
  double divider=1.0;
  if (clockSource == SRC_ACLK) {
    divider=1.0 * core.smclkFrq / core.aclkFrq;
  }
  divider=divider * inputDivider;
  long cycctr=cycles - counterStart;
  double tick=cycctr / divider;
  counterPassed=(int)(divider * (tick - (long)(tick)));
  counterStart=cycles - counterPassed;
  counterAcc=counter;
  updateCyclesMultiplicator();
  if (DEBUG)   System.out.println(getName() + "String_Node_Str" + cycles+ "String_Node_Str"+ cyclesMultiplicator);
  core.scheduleCycleEvent(counterTrigger,(long)((0x100000 - counter) * cyclesMultiplicator));
}

Fixed version (ground truth):
void resetCounter(long cycles){
  double divider=1.0;
  if (clockSource == SRC_ACLK) {
    divider=1.0 * core.smclkFrq / core.aclkFrq;
  }
  divider=divider * inputDivider;
  long cycctr=cycles - counterStart;
  double tick=cycctr / divider;
  counterPassed=(int)(divider * (tick - (long)(tick)));
  counterStart=cycles - counterPassed;
  counterAcc=counter;
  updateCyclesMultiplicator();
  if (DEBUG)   System.out.println(getName() + "String_Node_Str" + cycles+ "String_Node_Str"+ cyclesMultiplicator);
  core.scheduleCycleEvent(counterTrigger,cycles + (long)((0x10000 - counter) * cyclesMultiplicator));
}
Program: 5559
Project: 5559
Buggy source:
public void execute(long t){
  interruptPending=true;
  nextTimerTrigger=(long)(nextTimerTrigger + 0x10000 * cyclesMultiplicator);
  core.scheduleCycleEvent(this,nextTimerTrigger);
  if (lastTIV == 0 && interruptEnable) {
    lastTIV=memory[tiv]=timerOverflow;
    core.flagInterrupt(ccr1Vector,Timer.this,true);
  }
}

Fixed version (ground truth):
public void execute(long t){
  interruptPending=true;
  nextTimerTrigger=(long)(nextTimerTrigger + 0x10000 * cyclesMultiplicator);
  core.scheduleCycleEvent(this,nextTimerTrigger);
  if (lastTIV == 0 && interruptEnable) {
    lastTIV=memory[tiv]=timerOverflow;
    core.flagInterrupt(ccr1Vector,Timer.this,true);
  }
 else {
  }
}
Program: 5560
Project: 5560
Buggy source:
private void triggerAccessViolation(String reason){
  if (DEBUG)   log("String_Node_Str" + reason + "String_Node_Str"+ Utils.hex16(cpu.readRegister(MSP430.PC)));
  statusreg|=ACCVIFG;
  if (cpu.getSFR().isIEBitsSet(SFR.IE1,ACCVIE)) {
    cpu.flagInterrupt(NMI_VECTOR,this,true);
  }
}

Fixed version (ground truth):
private void triggerAccessViolation(String reason){
  logw("String_Node_Str" + reason + "String_Node_Str"+ Utils.hex16(cpu.readRegister(MSP430.PC)));
  statusreg|=ACCVIFG;
  if (cpu.getSFR().isIEBitsSet(SFR.IE1,ACCVIE)) {
    cpu.flagInterrupt(NMI_VECTOR,this,true);
  }
}
Program: 5561
Project: 5561
Buggy source:
private void triggerEndBlockWrite(){
  if (DEBUG) {
    log("String_Node_Str");
  }
  current_write_mode=WriteMode.WRITE_BLOCK_FINISH;
  waitFlashProcess(BLOCKWRITE_END_TIME);
}

Fixed version (ground truth):
private void triggerEndBlockWrite(){
  if (DEBUG) {
    log("String_Node_Str");
  }
  currentWriteMode=WriteMode.WRITE_BLOCK_FINISH;
  waitFlashProcess(BLOCKWRITE_END_TIME);
}
Program: 5562
Project: 5562
Buggy source:
private EraseMode getEraseMode(int regdata){
  int idx=(regdata & ERASE_MASK) >> ERASE_SHIFT;
  for (  EraseMode em : EraseMode.values()) {
    if (em.ordinal() == idx)     return em;
  }
  throw new IllegalArgumentException("String_Node_Str" + regdata);
}

Fixed version (ground truth):
private WriteMode getEraseMode(int regdata){
  int idx=(regdata & ERASE_MASK) >> ERASE_SHIFT;
  for (  WriteMode em : WriteMode.values()) {
    if (em.ordinal() == idx)     return em;
  }
  throw new IllegalArgumentException("String_Node_Str" + regdata);
}
Program: 5564
Project: 5564
Buggy source:
public Flash(MSP430Core cpu,int[] memory,FlashRange main_range,FlashRange info_range){
  super("String_Node_Str","String_Node_Str",memory,FCTL1);
  this.cpu=cpu;
  this.memory=memory;
  this.main_range=main_range;
  this.info_range=info_range;
  locked=true;
  reset(MSP430.RESET_POR);
}

Fixed version (ground truth):
public Flash(MSP430Core cpu,int[] memory,FlashRange main_range,FlashRange info_range){
  super("String_Node_Str","String_Node_Str",memory,FCTL1);
  this.cpu=cpu;
  this.memory=memory;
  this.main_range=main_range;
  this.info_range=info_range;
  locked=true;
  Arrays.fill(memory,main_range.start,main_range.end,0xff);
  Arrays.fill(memory,info_range.start,info_range.end,0xff);
  reset(MSP430.RESET_POR);
}
Program: 5565
Project: 5565
Buggy source:
public void write(int address,int value,boolean word,long cycles){
  if (!word) {
    logw("String_Node_Str");
    return;
  }
  if (!(address == FCTL1 || address == FCTL2 || address == FCTL3)) {
    return;
  }
  if (!checkKey(value)) {
    return;
  }
  int regdata=value & CMDMASK;
switch (address) {
case FCTL1:
    if ((mode & ERASE_MASK) != 0 || (mode & WRT) != 0) {
      if (!((mode & BLKWRT) != 0 && wait)) {
        triggerAccessViolation("String_Node_Str");
        return;
      }
    }
  if ((mode & ERASE_MASK) != (regdata & ERASE_MASK)) {
    if ((mode & ERASE_MASK) == 0) {
      triggerErase(regdata);
    }
    mode&=~ERASE_MASK;
    mode|=regdata & ERASE_MASK;
  }
if ((mode & WRT) != (regdata & WRT)) {
  if ((regdata & WRT) != 0) {
    if ((regdata & BLKWRT) != 0) {
      triggerBlockWrite();
      mode|=BLKWRT;
    }
 else {
      triggerSingleWrite();
    }
    mode&=~WRT;
    mode|=regdata & WRT;
  }
}
if ((mode & BLKWRT) != 0 && (regdata & BLKWRT) == 0) {
triggerEndBlockWrite();
mode&=~BLKWRT;
}
break;
case FCTL2:
if (busy) {
triggerAccessViolation("String_Node_Str");
return;
}
clockcfg=regdata;
break;
case FCTL3:
if ((statusreg & EMEX) == 0 && (regdata & EMEX) == 1) {
triggerEmergencyExit();
}
if (locked && (regdata & LOCK) == 0) {
triggerUnlockFlash();
}
 else {
if (!locked && (regdata & LOCK) != 0) {
triggerLockFlash();
}
}
if (((statusreg ^ regdata) & KEYV) != 0) {
statusreg^=KEYV;
}
if (((statusreg ^ regdata) & ACCVIFG) != 0) {
statusreg^=ACCVIFG;
}
break;
}
}

Fixed version (ground truth):
public void write(int address,int value,boolean word,long cycles){
  if (!word) {
    logw("String_Node_Str");
    return;
  }
  if (!(address == FCTL1 || address == FCTL2 || address == FCTL3)) {
    return;
  }
  if (!checkKey(value)) {
    return;
  }
  int regdata=value & CMDMASK;
switch (address) {
case FCTL1:
    if (busy && ((mode & BLKWRT) == 0 || wait == false)) {
      triggerAccessViolation("String_Node_Str");
      return;
    }
  if ((mode & ERASE_MASK) != (regdata & ERASE_MASK)) {
    if ((mode & ERASE_MASK) == 0) {
      triggerErase(regdata);
    }
    mode&=~ERASE_MASK;
    mode|=regdata & ERASE_MASK;
  }
if ((mode & WRT) != (regdata & WRT)) {
  if ((regdata & WRT) != 0) {
    if ((regdata & BLKWRT) != 0) {
      triggerBlockWrite();
      mode|=BLKWRT;
    }
 else {
      triggerSingleWrite();
    }
  }
  mode&=~WRT;
  mode|=regdata & WRT;
}
if ((mode & BLKWRT) != 0 && (regdata & BLKWRT) == 0) {
triggerEndBlockWrite();
mode&=~BLKWRT;
}
break;
case FCTL2:
if (busy) {
triggerAccessViolation("String_Node_Str");
return;
}
clockcfg=regdata;
break;
case FCTL3:
if ((statusreg & EMEX) == 0 && (regdata & EMEX) == 1) {
triggerEmergencyExit();
}
if (locked && (regdata & LOCK) == 0) {
triggerUnlockFlash();
}
 else {
if (!locked && (regdata & LOCK) != 0) {
triggerLockFlash();
}
}
if (((statusreg ^ regdata) & KEYV) != 0) {
statusreg^=KEYV;
}
if (((statusreg ^ regdata) & ACCVIFG) != 0) {
statusreg^=ACCVIFG;
}
break;
}
}
Program: 5566
Project: 5566
Buggy source:
private void triggerEmergencyExit(){
  mode=0;
  busy=false;
  wait=true;
  locked=true;
  current_erase=EraseMode.ERASE_NONE;
  current_write_mode=WriteMode.WRITE_NONE;
}

Fixed version (ground truth):
private void triggerEmergencyExit(){
  mode=0;
  busy=false;
  wait=true;
  locked=true;
  currentWriteMode=WriteMode.NONE;
}
Program: 5567
Project: 5567
Buggy source:
public void notifyRead(int address){
  if (busy) {
    triggerAccessViolation("String_Node_Str");
    return;
  }
  if (DEBUG) {
    if (wait == false && current_write_mode == WriteMode.WRITE_BLOCK) {
      log("String_Node_Str");
      log("String_Node_Str" + Utils.hex16(cpu.readRegister(MSP430.PC)) + "String_Node_Str"+ Utils.hex16(address));
    }
  }
}

Fixed version (ground truth):
public void notifyRead(int address){
  if (busy) {
    triggerAccessViolation("String_Node_Str");
    return;
  }
  if (DEBUG) {
    if (wait == false && currentWriteMode == WriteMode.WRITE_BLOCK) {
      log("String_Node_Str");
      log("String_Node_Str" + Utils.hex16(cpu.readRegister(MSP430.PC)) + "String_Node_Str"+ Utils.hex16(address));
    }
  }
}
Program: 5568
Project: 5568
Buggy source:
private void triggerBlockWrite(){
  if (DEBUG) {
    log("String_Node_Str");
  }
  current_write_mode=WriteMode.WRITE_BLOCK;
  blockwrite_count=0;
}

Fixed version (ground truth):
private void triggerBlockWrite(){
  if (DEBUG) {
    log("String_Node_Str");
  }
  currentWriteMode=WriteMode.WRITE_BLOCK;
  blockwriteCount=0;
}
Program: 5569
Project: 5569
Buggy source:
private void triggerErase(int newmode){
  current_erase=getEraseMode(newmode);
}

Fixed version (ground truth):
private void triggerErase(int newmode){
  currentWriteMode=getEraseMode(newmode);
}
Program: 5570
Project: 5570
Buggy source:
public void reset(int type){
  if (DEBUG) {
    log("String_Node_Str");
  }
  if (type == MSP430.RESET_POR)   statusreg=0;
  mode=0;
  clockcfg=0x42;
  busy=false;
  wait=true;
  locked=true;
  current_erase=EraseMode.ERASE_NONE;
  current_write_mode=WriteMode.WRITE_NONE;
}

Fixed version (ground truth):
public void reset(int type){
  if (DEBUG) {
    log("String_Node_Str");
  }
  if (type == MSP430.RESET_POR)   statusreg=0;
  mode=0;
  clockcfg=0x42;
  busy=false;
  wait=true;
  locked=true;
  currentWriteMode=WriteMode.NONE;
}
Program: 5571
Project: 5571
Buggy source:
private void triggerSingleWrite(){
  current_write_mode=WriteMode.WRITE_SINGLE;
}

Fixed version (ground truth):
private void triggerSingleWrite(){
  currentWriteMode=WriteMode.WRITE_SINGLE;
}
Program: 5572
Project: 5572
Buggy source:
public void registerComponent(String name,Object component){
synchronized (components) {
    components.add(new ComponentEntry(name,component));
  }
  if (component instanceof ActiveComponent) {
    ((ActiveComponent)component).init(name,this);
    if (running) {
      ((ActiveComponent)component).start();
    }
  }
 else   if (component instanceof ServiceComponent) {
    ((ServiceComponent)component).init(name,this);
  }
}

Fixed version (ground truth):
public void registerComponent(String name,Object component){
synchronized (this) {
    components.add(new ComponentEntry(name,component));
  }
  if (component instanceof ActiveComponent) {
    ((ActiveComponent)component).init(name,this);
    if (running) {
      ((ActiveComponent)component).start();
    }
  }
 else   if (component instanceof ServiceComponent) {
    ((ServiceComponent)component).init(name,this);
  }
}
Program: 5573
Project: 5573
Buggy source:
public CC2420(MSP430Core cpu){
  rxFIFO=new ArrayFIFO(memory,RAM_RXFIFO,128);
  registers[REG_SNOP]=0;
  registers[REG_TXCTRL]=0xa0ff;
  this.cpu=cpu;
  setModeNames(MODE_NAMES);
  setMode(MODE_POWER_OFF);
  fifoP=false;
  rxFIFO.reset();
  overflow=false;
  reset();
  cpu.addChip(this);
}

Fixed version (ground truth):
public CC2420(MSP430Core cpu){
  rxFIFO=new ArrayFIFO("String_Node_Str",memory,RAM_RXFIFO,128);
  registers[REG_SNOP]=0;
  registers[REG_TXCTRL]=0xa0ff;
  this.cpu=cpu;
  setModeNames(MODE_NAMES);
  setMode(MODE_POWER_OFF);
  fifoP=false;
  rxFIFO.reset();
  overflow=false;
  reset();
  cpu.addChip(this);
}
Program: 5574
Project: 5574
Buggy source:
public void write(int address,int value,boolean word,long cycles){
  if (address == WDTCTL) {
    if ((value >> 8) == 0x5a) {
      wdtctl=value & 0xff;
      if (DEBUG)       System.out.println(getName() + "String_Node_Str" + Utils.hex8(wdtctl));
      wdtOn=(value & 0x80) == 0;
      boolean lastACLK=sourceACLK;
      sourceACLK=(value & WDTSSEL) != 0;
      if ((value & WDTCNTCL) != 0) {
        delay=DELAY[value & WDTISx];
      }
      timerMode=(value & WDTMSEL) != 0;
      if (wdtOn) {
        if (DEBUG)         System.out.println("String_Node_Str" + delay);
        scheduleTimer();
      }
 else {
        wdtTrigger.remove();
      }
    }
 else {
      cpu.flagInterrupt(RESET_VECTOR,this,true);
    }
  }
}

Fixed version (ground truth):
public void write(int address,int value,boolean word,long cycles){
  if (address == WDTCTL) {
    if ((value >> 8) == 0x5a) {
      wdtctl=value & 0xff;
      if (DEBUG)       System.out.println(getName() + "String_Node_Str" + Utils.hex8(wdtctl)+ "String_Node_Str"+ cpu.getPC());
      wdtOn=(value & 0x80) == 0;
      boolean lastACLK=sourceACLK;
      sourceACLK=(value & WDTSSEL) != 0;
      if ((value & WDTCNTCL) != 0) {
        delay=DELAY[value & WDTISx];
      }
      timerMode=(value & WDTMSEL) != 0;
      if (wdtOn) {
        if (DEBUG)         System.out.println("String_Node_Str" + delay);
        scheduleTimer();
      }
 else {
        wdtTrigger.remove();
      }
    }
 else {
      cpu.flagInterrupt(RESET_VECTOR,this,true);
    }
  }
}
Program: 5575
Project: 5575
Buggy source:
public int read(){
  int v=memory[start + readPos++];
  if (readPos >= size) {
    readPos=0;
  }
  len--;
  if (len < 0) {
    if (STRICT) {
      throw new EmulationException("String_Node_Str");
    }
 else {
      System.out.println("String_Node_Str");
    }
  }
  return v & 0xff;
}

Fixed version (ground truth):
public int read(){
  if (len <= 0) {
    if (STRICT) {
      throw new EmulationException("String_Node_Str");
    }
 else {
      System.out.println("String_Node_Str");
      return 0;
    }
  }
  int v=memory[start + readPos++];
  if (readPos >= size) {
    readPos=0;
  }
  len--;
  return v & 0xff;
}
Program: 5576
Project: 5576
Buggy source:
public String stateToString(){
  return "String_Node_Str" + len + "String_Node_Str"+ readPos+ "String_Node_Str"+ writePos;
}

Fixed version (ground truth):
public String stateToString(){
  return name + "String_Node_Str" + len+ "String_Node_Str"+ readPos+ "String_Node_Str"+ writePos;
}
Program: 5577
Project: 5577
Buggy source:
public ArrayFIFO(int[] mem,int start,int size){
  memory=mem;
  this.start=start;
  this.size=size;
  len=0;
}

Fixed version (ground truth):
public ArrayFIFO(String name,int[] mem,int start,int size){
  memory=mem;
  this.name=name;
  this.start=start;
  this.size=size;
  len=0;
}
Program: 5579
Project: 5579
Buggy source:
private int rev8bits(int v){
  int r=0;
  int s=7;
  for (v>>=1; v > 0; v>>=1) {
    r<<=1;
    r|=v & 1;
    s--;
  }
  r<<=s;
  return r;
}

Fixed version (ground truth):
private static int rev8bits(int v){
  int r=0;
  int s=8;
  while (v > 0) {
    r=(r << 1) | v & 1;
    v=(v >> 1) & 0xff;
    s--;
  }
  r<<=s;
  return r & 0xff;
}
Program: 5580
Project: 5580
Buggy source:
private int crc8Add(int acc,int data){
  int i;
  acc^=data;
  for (i=0; i < 8; i++) {
    if ((acc & 0x80) != 0) {
      acc=(acc << 1) ^ 0x31;
    }
 else {
      acc<<=1;
    }
  }
  return acc & 0xff;
}

Fixed version (ground truth):
private int crc8Add(int acc,int data){
  int i;
  acc^=(data & 0xff);
  for (i=0; i < 8; i++) {
    if ((acc & 0x80) != 0) {
      acc=((acc << 1) ^ 0x31) & 0xff;
    }
 else {
      acc<<=1;
    }
  }
  return acc & 0xff;
}
Program: 5581
Project: 5581
Buggy source:
public void execute(long t){
  if (readData == CMD_MEASURE_TEMP) {
    output[0]=temp >> 8;
    output[1]=temp & 0xff;
  }
 else   if (readData == CMD_MEASURE_HUM) {
    output[0]=humid >> 8;
    output[1]=humid & 0xff;
  }
 else {
    return;
  }
  int crc=0;
  crc=crc8Add(crc,readData);
  crc=crc8Add(crc,output[0]);
  crc=crc8Add(crc,output[1]);
  if (DEBUG)   System.out.println("String_Node_Str" + crc + "String_Node_Str"+ rev8bits(crc));
  output[2]=rev8bits(crc);
  sdataPort.setPinState(sdataPin,IOPort.PIN_LOW);
  state=WRITE_BYTE;
  writeData=output[0];
  writePos=0;
  writeLen=3;
}

Fixed version (ground truth):
public void execute(long t){
  if (readData == CMD_MEASURE_TEMP) {
    output[0]=(temp >> 8) & 0xff;
    output[1]=temp & 0xff;
  }
 else   if (readData == CMD_MEASURE_HUM) {
    output[0]=(humid >> 8) & 0xff;
    output[1]=humid & 0xff;
  }
 else {
    return;
  }
  temp+=1;
  humid+=1;
  int crc=0;
  crc=crc8Add(crc,readData);
  crc=crc8Add(crc,output[0]);
  crc=crc8Add(crc,output[1]);
  if (DEBUG)   System.out.println("String_Node_Str" + Utils.hex8(crc) + "String_Node_Str"+ Utils.hex8(rev8bits(crc)));
  output[2]=rev8bits(crc);
  sdataPort.setPinState(sdataPin,IOPort.PIN_LOW);
  state=WRITE_BYTE;
  writeData=output[0];
  writePos=0;
  writeLen=3;
}
Program: 5582
Project: 5582
Buggy source:
public void interruptServiced(int vector){
  irqTriggered[vector]=false;
  int pos=irqTriggeredPos[vector];
  int bit=pos & 7;
  if (pos > 8) {
    ifg1&=~(1 << bit);
  }
 else {
    ifg2&=~(1 << bit);
  }
  cpu.flagInterrupt(vector,this,false);
  if (sfrModule[pos] != null) {
    sfrModule[pos].interruptServiced(vector);
  }
}

Fixed version (ground truth):
public void interruptServiced(int vector){
  irqTriggered[vector]=false;
  int pos=irqTriggeredPos[vector];
  int bit=pos & 7;
  if (pos < 8) {
    ifg1&=~(1 << bit);
  }
 else {
    ifg2&=~(1 << bit);
  }
  cpu.flagInterrupt(vector,this,false);
  if (sfrModule[pos] != null) {
    sfrModule[pos].interruptServiced(vector);
  }
}
Program: 5583
Project: 5583
Buggy source:
public void write(int address,int value,boolean word,long cycles){
  if (DEBUG)   System.out.println(getName() + "String_Node_Str" + address+ "String_Node_Str"+ value);
switch (address) {
case IE1:
case IE2:
    updateIE(address - IE1,value);
  break;
case IFG1:
case IFG2:
updateIFG(address - IFG1,value);
break;
case ME1:
case ME2:
updateME(address - ME1,value);
default :
memory[address]=value;
}
}

Fixed version (ground truth):
public void write(int address,int value,boolean word,long cycles){
  if (DEBUG)   System.out.println(getName() + "String_Node_Str" + address+ "String_Node_Str"+ value);
switch (address) {
case IE1:
case IE2:
    updateIE(address - IE1,value);
  break;
case IFG1:
case IFG2:
updateIFG(address - IFG1,value);
break;
case ME1:
case ME2:
updateME(address - ME1,value);
}
memory[address]=value;
}
Program: 5584
Project: 5584
Buggy source:
public void reset(int type){
  nextTXReady=cpu.cycles + 100;
  txShiftReg=nextTXByte=-1;
  transmitting=false;
  clrBitIFG(urxifg);
  setBitIFG(utxifg);
  utctl|=UTCTL_TXEMPTY;
  cpu.scheduleCycleEvent(txTrigger,nextTXReady);
  txEnabled=false;
  rxEnabled=false;
}

Fixed version (ground truth):
public void reset(int type){
  nextTXReady=cpu.cycles + 100;
  txShiftReg=nextTXByte=-1;
  transmitting=false;
  clrBitIFG(urxifg);
  setBitIFG(utxifg);
  utctl|=UTCTL_TXEMPTY;
  txEnabled=false;
  rxEnabled=false;
}
Program: 5585
Project: 5585
Buggy source:
public void interruptServiced(int vector){
  irqTriggered[vector]=false;
  int pos=irqTriggeredPos[vector];
  if (autoclear[vector]) {
    int bit=pos & 7;
    if (pos < 8) {
      ifg1&=~(1 << bit);
    }
 else {
      ifg2&=~(1 << bit);
    }
  }
  cpu.flagInterrupt(vector,this,false);
  if (sfrModule[pos] != null) {
    sfrModule[pos].interruptServiced(vector);
  }
}

Fixed version (ground truth):
public void interruptServiced(int vector){
  irqTriggered[vector]=false;
  int pos=irqTriggeredPos[vector];
  if (autoclear[vector]) {
    int bit=pos & 7;
    if (pos < 8) {
      ifg1&=~(1 << bit);
    }
 else {
      ifg2&=~(1 << bit);
    }
    if (DEBUG) {
      System.out.println("String_Node_Str" + sfrModule[pos] + "String_Node_Str"+ vector);
    }
  }
  cpu.flagInterrupt(vector,this,false);
  if (sfrModule[pos] != null) {
    sfrModule[pos].interruptServiced(vector);
  }
}
Program: 5586
Project: 5586
Buggy source:
private void updateIRQ(int pos,int change){
  int ifg=pos == 0 ? ifg1 : ifg2;
  int ie=pos == 0 ? ie1 : ie2;
  pos=pos * 8;
  for (int i=0; i < 8; i++) {
    if ((change & 1) == 1) {
      if (sfrModule[pos] != null && !irqTriggered[irqVector[pos]]) {
        if (DEBUG)         System.out.println("String_Node_Str" + sfrModule[pos].getName() + "String_Node_Str"+ pos+ "String_Node_Str"+ (ie & ifg & 1)+ "String_Node_Str"+ change);
        if ((ie & ifg & 1) > 0) {
          int vector=irqVector[pos];
          irqTriggered[vector]=true;
          irqTriggeredPos[vector]=pos;
          cpu.flagInterrupt(irqVector[pos],this,true);
        }
      }
    }
    pos++;
    change=change >> 1;
    ifg=ifg >> 1;
    ie=ie >> 1;
  }
}

Fixed version (ground truth):
private void updateIRQ(int pos,int change){
  int ifg=pos == 0 ? ifg1 : ifg2;
  int ie=pos == 0 ? ie1 : ie2;
  pos=pos * 8;
  for (int i=0; i < 8; i++) {
    if ((change & 1) == 1) {
      if (sfrModule[pos] != null && !irqTriggered[irqVector[pos]]) {
        if (DEBUG)         System.out.println("String_Node_Str" + sfrModule[pos].getName() + "String_Node_Str"+ pos+ "String_Node_Str"+ (ie & 1)+ "String_Node_Str"+ (ifg & 1)+ "String_Node_Str"+ change);
        if ((ie & ifg & 1) > 0) {
          int vector=irqVector[pos];
          irqTriggered[vector]=true;
          irqTriggeredPos[vector]=pos;
          cpu.flagInterrupt(vector,this,true);
        }
      }
    }
    pos++;
    change=change >> 1;
    ifg=ifg >> 1;
    ie=ie >> 1;
  }
}
Program: 5587
Project: 5587
Buggy source:
private void triggerWDT(long time){
  if (timerMode) {
    SFR sfr=cpu.getSFR();
    sfr.setBitIFG(0,WATCHDOG_INTERRUPT_BIT);
    scheduleTimer();
  }
 else {
    System.out.println("String_Node_Str");
    cpu.generateTrace(System.out);
    cpu.flagInterrupt(RESET_VECTOR,this,true);
  }
}

Fixed version (ground truth):
private void triggerWDT(long time){
  if (timerMode) {
    SFR sfr=cpu.getSFR();
    sfr.setBitIFG(0,WATCHDOG_INTERRUPT_VALUE);
    scheduleTimer();
  }
 else {
    System.out.println("String_Node_Str");
    cpu.generateTrace(System.out);
    cpu.flagInterrupt(RESET_VECTOR,this,true);
  }
}
Program: 5591
Project: 5591
Buggy source:
private void flushRX(){
  if (DEBUG) {
    log("String_Node_Str" + rxfifoLen);
  }
  rxfifoReadPos=0;
  rxfifoWritePos=0;
  rxfifoLen=0;
  setSFD(false);
  setFIFOP(false);
  setFIFO(false);
  overflow=false;
  if ((stateMachine == RadioState.RX_CALIBRATE) || (stateMachine == RadioState.RX_SFD_SEARCH) || (stateMachine == RadioState.RX_FRAME)|| (stateMachine == RadioState.RX_OVERFLOW)|| (stateMachine == RadioState.RX_WAIT)) {
    setState(RadioState.RX_SFD_SEARCH);
  }
}

Fixed version (ground truth):
private void flushRX(){
  if (DEBUG) {
    log("String_Node_Str" + rxfifoLen);
  }
  rxfifoReadPos=0;
  rxfifoReadLeft=0;
  rxfifoWritePos=0;
  rxfifoLen=0;
  setSFD(false);
  setFIFOP(false);
  setFIFO(false);
  overflow=false;
  if ((stateMachine == RadioState.RX_CALIBRATE) || (stateMachine == RadioState.RX_SFD_SEARCH) || (stateMachine == RadioState.RX_FRAME)|| (stateMachine == RadioState.RX_OVERFLOW)|| (stateMachine == RadioState.RX_WAIT)) {
    setState(RadioState.RX_SFD_SEARCH);
  }
}
Program: 5592
Project: 5592
Buggy source:
private boolean setState(RadioState state){
  if (DEBUG)   log("String_Node_Str" + stateMachine + "String_Node_Str"+ state);
  stateMachine=state;
  registers[REG_FSMSTATE]=state.getFSMState();
switch (stateMachine) {
case VREG_OFF:
    if (DEBUG)     log("String_Node_Str");
  flushRX();
flushTX();
status&=~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE);
reset();
setMode(MODE_POWER_OFF);
updateCCA();
break;
case POWER_DOWN:
rxfifoReadPos=0;
rxfifoWritePos=0;
status&=~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE);
reset();
setMode(MODE_POWER_OFF);
updateCCA();
break;
case RX_CALIBRATE:
setSymbolEvent(8);
setMode(MODE_RX_ON);
break;
case RX_SFD_SEARCH:
zeroSymbols=0;
status|=STATUS_RSSI_VALID;
updateCCA();
setMode(MODE_RX_ON);
break;
case TX_CALIBRATE:
setSymbolEvent(12 + 2);
setMode(MODE_TXRX_ON);
break;
case TX_PREAMBLE:
shrPos=0;
SHR[0]=0;
SHR[1]=0;
SHR[2]=0;
SHR[3]=0;
SHR[4]=0x7A;
shrNext();
break;
case TX_FRAME:
txfifoPos=0;
txNext();
break;
case RX_WAIT:
setSymbolEvent(8);
setMode(MODE_RX_ON);
break;
case IDLE:
status&=~STATUS_RSSI_VALID;
setMode(MODE_TXRX_OFF);
updateCCA();
break;
case TX_ACK_CALIBRATE:
status|=STATUS_TX_ACTIVE;
setSymbolEvent(12 + 2);
setMode(MODE_TXRX_ON);
break;
case TX_ACK_PREAMBLE:
shrPos=0;
SHR[0]=0;
SHR[1]=0;
SHR[2]=0;
SHR[3]=0;
SHR[4]=0x7A;
shrNext();
break;
case TX_ACK:
ackPos=0;
ackNext();
break;
}
if (stateListener != null) {
stateListener.newState(stateMachine);
}
return true;
}

Fixed version (ground truth):
private boolean setState(RadioState state){
  if (DEBUG)   log("String_Node_Str" + stateMachine + "String_Node_Str"+ state);
  stateMachine=state;
  registers[REG_FSMSTATE]=state.getFSMState();
switch (stateMachine) {
case VREG_OFF:
    if (DEBUG)     log("String_Node_Str");
  flushRX();
flushTX();
status&=~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE);
reset();
setMode(MODE_POWER_OFF);
updateCCA();
break;
case POWER_DOWN:
rxfifoReadPos=0;
rxfifoReadLeft=0;
rxfifoWritePos=0;
status&=~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE);
reset();
setMode(MODE_POWER_OFF);
updateCCA();
break;
case RX_CALIBRATE:
setSymbolEvent(8);
setMode(MODE_RX_ON);
break;
case RX_SFD_SEARCH:
zeroSymbols=0;
status|=STATUS_RSSI_VALID;
updateCCA();
setMode(MODE_RX_ON);
break;
case TX_CALIBRATE:
setSymbolEvent(12 + 2);
setMode(MODE_TXRX_ON);
break;
case TX_PREAMBLE:
shrPos=0;
SHR[0]=0;
SHR[1]=0;
SHR[2]=0;
SHR[3]=0;
SHR[4]=0x7A;
shrNext();
break;
case TX_FRAME:
txfifoPos=0;
txNext();
break;
case RX_WAIT:
setSymbolEvent(8);
setMode(MODE_RX_ON);
break;
case IDLE:
status&=~STATUS_RSSI_VALID;
setMode(MODE_TXRX_OFF);
updateCCA();
break;
case TX_ACK_CALIBRATE:
status|=STATUS_TX_ACTIVE;
setSymbolEvent(12 + 2);
setMode(MODE_TXRX_ON);
break;
case TX_ACK_PREAMBLE:
shrPos=0;
SHR[0]=0;
SHR[1]=0;
SHR[2]=0;
SHR[3]=0;
SHR[4]=0x7A;
shrNext();
break;
case TX_ACK:
ackPos=0;
ackNext();
break;
}
if (stateListener != null) {
stateListener.newState(stateMachine);
}
return true;
}
Program: 5593
Project: 5593
Buggy source:
private boolean checkAutoack(){
  boolean ackReq=(memory[RAM_RXFIFO + lastPacketStart] & ACK_REQUEST) != 0;
  if (!ackReq)   return false;
  System.out.println("String_Node_Str");
  int destAddrMode=(memory[RAM_RXFIFO + (lastPacketStart + 1) & 127] >> 2) & 3;
  if (destAddrMode == LONG_ADDRESS) {
    int addrSize=8;
    int addrPos=lastPacketStart + 5;
    for (int i=0; i < addrSize; i++) {
      System.out.println("String_Node_Str" + i + "String_Node_Str"+ memory[RAM_IEEEADDR + i]+ "String_Node_Str"+ memory[RAM_RXFIFO + ((addrPos + i) & 127)]);
      if (memory[RAM_IEEEADDR + i] != memory[RAM_RXFIFO + ((addrPos + i) & 127)]) {
        return false;
      }
    }
  }
 else {
    int addrPos=lastPacketStart + 5;
    for (int i=0; i < 2; i++) {
      System.out.println("String_Node_Str" + i + "String_Node_Str"+ memory[RAM_SHORTADDR + i]+ "String_Node_Str"+ memory[RAM_RXFIFO + ((addrPos + i) & 127)]);
      if (memory[RAM_SHORTADDR + i] != memory[RAM_RXFIFO + ((addrPos + i) & 127)]) {
        return false;
      }
    }
  }
  System.out.println("String_Node_Str" + memory[RAM_IEEEADDR]);
  return true;
}

Fixed version (ground truth):
private boolean checkAutoack(){
  boolean ackReq=(memory[RAM_RXFIFO + lastPacketStart] & ACK_REQUEST) != 0;
  if (!ackReq)   return false;
  return true;
}
Program: 5597
Project: 5597
Buggy source:
@Override public int executeCommand(CommandContext context){
  if ("String_Node_Str".equals(context.getArgument(0))) {
    int size=cpu.getTraceSize();
    DisAsm disAsm=cpu.getDisAsm();
    for (int i=0; i < size; i++) {
      int pc=cpu.getBackTrace(i);
      DbgInstruction inst=disAsm.getDbgInstruction(pc,cpu);
      inst.setPos(pc);
      System.out.println(inst);
    }
  }
 else {
    cpu.setTrace(context.getArgumentAsInt(0));
  }
  return 0;
}

Fixed version (ground truth):
@Override public int executeCommand(CommandContext context){
  if ("String_Node_Str".equals(context.getArgument(0))) {
    int size=cpu.getTraceSize();
    DisAsm disAsm=cpu.getDisAsm();
    for (int i=0; i < size; i++) {
      int pc=cpu.getBackTrace(size - 1 - i);
      DbgInstruction inst=disAsm.getDbgInstruction(pc,cpu);
      inst.setPos(pc);
      System.out.println(inst);
    }
  }
 else {
    cpu.setTrace(context.getArgumentAsInt(0));
  }
  return 0;
}
Program: 5599
Project: 5599
Buggy source:
public void setDCOFrq(int frequency,int smclkFrq){
  dcoFrq=frequency;
  this.smclkFrq=smclkFrq;
  lastVTime=getTime();
  lastCyclesTime=cycles;
  lastMicrosDelta=0;
  currentDCOFactor=1.0 * BasicClockModule.MAX_DCO_FRQ / frequency;
  if (DEBUG)   System.out.println("String_Node_Str" + smclkFrq);
}

Fixed version (ground truth):
public void setDCOFrq(int frequency,int smclkFrq){
  dcoFrq=frequency;
  this.smclkFrq=smclkFrq;
  lastVTime=getTime();
  lastCyclesTime=cycles;
  lastMicrosDelta=0;
  currentDCOFactor=1.0 * BasicClockModule.MAX_DCO_FRQ / frequency;
  if (DEBUG)   System.out.println("String_Node_Str" + smclkFrq);
  dcoReset();
}
Program: 5601
Project: 5601
Buggy source:
private void updateTCCTL(int cctl,long cycles){
  boolean input=false;
  if (inputSrc[cctl] == SRC_ACLK) {
    int aTicks=clockSpeed / core.aclkFrq;
    updateCounter(cycles);
    if (counter % aTicks > aTicks / 2) {
      input=true;
    }
  }
  tcctl[cctl]=(tcctl[cctl] & ~CC_I) | (input ? CC_I : 0);
}

Fixed version (ground truth):
private void updateTCCTL(int cctl,long cycles){
  boolean input=false;
  if (inputSrc[cctl] == SRC_ACLK) {
    int aTicks=clockSpeed / core.aclkFrq;
    updateCounter(cycles);
    if (aTicks > 0 && counter % aTicks > aTicks / 2) {
      input=true;
    }
  }
  tcctl[cctl]=(tcctl[cctl] & ~CC_I) | (input ? CC_I : 0);
}
Program: 5603
Project: 5603
Buggy source:
public void setupNode(){
  setupNodePorts();
  stats.addMonitor(this);
  stats.addMonitor(radio);
  stats.addMonitor(cpu);
  if (!config.getPropertyAsBoolean("String_Node_Str",true)) {
    gui=new ESBGui(this);
    DataChart dataChart=new DataChart("String_Node_Str","String_Node_Str");
    DataSourceSampler dss=dataChart.setupChipFrame(cpu);
    dataChart.addDataSource(dss,"String_Node_Str",stats.getDataSource("String_Node_Str",TR1001.MODE_RX_ON));
    dataChart.addDataSource(dss,"String_Node_Str",stats.getDataSource("String_Node_Str",TR1001.MODE_TXRX_ON));
    dataChart.addDataSource(dss,"String_Node_Str",stats.getDataSource("String_Node_Str",MSP430.MODE_ACTIVE));
  }
}

Fixed version (ground truth):
public void setupNode(){
  setupNodePorts();
  stats.addMonitor(this);
  stats.addMonitor(radio);
  stats.addMonitor(cpu);
  if (!config.getPropertyAsBoolean("String_Node_Str",true)) {
    gui=new ESBGui(this);
    DataChart dataChart=new DataChart(registry,"String_Node_Str","String_Node_Str");
    DataSourceSampler dss=dataChart.setupChipFrame(cpu);
    dataChart.addDataSource(dss,"String_Node_Str",stats.getDataSource("String_Node_Str",TR1001.MODE_RX_ON));
    dataChart.addDataSource(dss,"String_Node_Str",stats.getDataSource("String_Node_Str",TR1001.MODE_TXRX_ON));
    dataChart.addDataSource(dss,"String_Node_Str",stats.getDataSource("String_Node_Str",MSP430.MODE_ACTIVE));
  }
}
Program: 5605
Project: 5605
Buggy source:
public byte[] parseAddress(String addressStr){
  byte[] address=new byte[16];
  int hexVal=0;
  int pos=0;
  int splitPos=0;
  addressStr=addressStr.toLowerCase();
  for (int i=0; i < addressStr.length() && pos < 16; i++) {
    char c=addressStr.charAt(i);
    if (c == ':') {
      address[pos++]=(byte)(hexVal >> 8);
      address[pos++]=(byte)(hexVal & 0xff);
      if (i + 1 < addressStr.length() && addressStr.charAt(i + 1) == ':') {
        splitPos=pos;
      }
      hexVal=0;
    }
 else     if (c >= '0' && c <= '9') {
      hexVal=(hexVal << 4) + c - '0';
    }
 else     if (c >= 'a' && c <= 'f') {
      hexVal=(hexVal << 4) + c - 'a' + 10;
    }
  }
  if (splitPos != 0) {
  }
  return address;
}

Fixed version (ground truth):
public static byte[] parseAddress(String addressStr){
  byte[] address=new byte[16];
  int hexVal=0;
  int pos=0;
  int splitPos=0;
  addressStr=addressStr.toLowerCase();
  for (int i=0; i < addressStr.length() && pos < 16; i++) {
    char c=addressStr.charAt(i);
    if (c == ':') {
      address[pos++]=(byte)(hexVal >> 8);
      address[pos++]=(byte)(hexVal & 0xff);
      if (i + 1 < addressStr.length() && addressStr.charAt(i + 1) == ':') {
        splitPos=pos;
      }
      hexVal=0;
    }
 else     if (c >= '0' && c <= '9') {
      hexVal=(hexVal << 4) + c - '0';
    }
 else     if (c >= 'a' && c <= 'f') {
      hexVal=(hexVal << 4) + c - 'a' + 10;
    }
  }
  if (splitPos != 0) {
  }
  return address;
}
Program: 5607
Project: 5607
Buggy source:
private int serviceInterrupt(int pc){
  int pcBefore=pc;
  int spBefore=readRegister(SP);
  int sp=spBefore;
  int sr=readRegister(SR);
  if (profiler != null) {
    profiler.profileInterrupt(interruptMax,cycles);
  }
  if (flash.blocksCPU()) {
    throw new IllegalStateException("String_Node_Str");
  }
  if (interruptMax < 15) {
    writeRegister(SP,sp=spBefore - 2);
    memory[sp]=pc & 0xff;
    memory[sp + 1]=(pc >> 8) & 0xff;
    writeRegister(SP,sp=sp - 2);
    memory[sp]=sr & 0xff;
    memory[sp + 1]=(sr >> 8) & 0xff;
  }
  writeRegister(PC,pc=memory[0xffe0 + interruptMax * 2] + (memory[0xffe0 + interruptMax * 2 + 1] << 8));
  writeRegister(SR,sr & ~CPUOFF & ~SCG1& ~OSCOFF);
  servicedInterrupt=interruptMax;
  servicedInterruptUnit=interruptSource[servicedInterrupt];
  reevaluateInterrupts();
  if (servicedInterrupt == 15) {
    internalReset();
  }
  cycles+=6;
  if (debugInterrupts) {
    System.out.println("String_Node_Str" + servicedInterrupt + "String_Node_Str"+ pcBefore+ "String_Node_Str"+ pc+ "String_Node_Str"+ spBefore);
  }
  if (servicedInterruptUnit != null) {
    if (debugInterrupts) {
      System.out.println("String_Node_Str" + servicedInterruptUnit.getName());
    }
    servicedInterruptUnit.interruptServiced(servicedInterrupt);
  }
  return pc;
}

Fixed version (ground truth):
private int serviceInterrupt(int pc){
  int pcBefore=pc;
  int spBefore=readRegister(SP);
  int sp=spBefore;
  int sr=readRegister(SR);
  if (profiler != null) {
    profiler.profileInterrupt(interruptMax,cycles);
  }
  if (flash.blocksCPU()) {
    throw new IllegalStateException("String_Node_Str");
  }
  if (interruptMax < 15) {
    writeRegister(SP,sp=spBefore - 2);
    memory[sp]=pc & 0xff;
    memory[sp + 1]=(pc >> 8) & 0xff;
    writeRegister(SP,sp=sp - 2);
    memory[sp]=sr & 0xff;
    memory[sp + 1]=(sr >> 8) & 0xff;
  }
  writeRegister(SR,0);
  writeRegister(PC,pc=memory[0xffe0 + interruptMax * 2] + (memory[0xffe0 + interruptMax * 2 + 1] << 8));
  servicedInterrupt=interruptMax;
  servicedInterruptUnit=interruptSource[servicedInterrupt];
  reevaluateInterrupts();
  if (servicedInterrupt == 15) {
    internalReset();
  }
  cycles+=6;
  if (debugInterrupts) {
    System.out.println("String_Node_Str" + servicedInterrupt + "String_Node_Str"+ pcBefore+ "String_Node_Str"+ pc+ "String_Node_Str"+ spBefore);
  }
  if (servicedInterruptUnit != null) {
    if (debugInterrupts) {
      System.out.println("String_Node_Str" + servicedInterruptUnit.getName());
    }
    servicedInterruptUnit.interruptServiced(servicedInterrupt);
  }
  return pc;
}