Program: 5563
Project: 5563
Buggy source:
public void flashWrite(int address,int data,boolean word){
  int wait_time=-1;
  if (locked) {
    if (DEBUG) {
      log("String_Node_Str");
    }
    return;
  }
  if (busy || wait == false) {
    if (!((mode & BLKWRT) != 0 && wait)) {
      triggerAccessViolation("String_Node_Str");
      return;
    }
  }
switch (current_erase) {
case ERASE_SEGMENT:
    int a_area_start[]=new int[1];
  int a_area_end[]=new int[1];
getSegmentRange(address,a_area_start,a_area_end);
int area_start=a_area_start[0];
int area_end=a_area_end[0];
if (DEBUG) {
log("String_Node_Str" + Utils.hex16(address) + "String_Node_Str"+ Utils.hex16(area_start)+ "String_Node_Str"+ Utils.hex16(area_end));
}
for (int i=area_start; i < area_end; i++) {
memory[i]=0xff;
}
waitFlashProcess(SEGMENT_ERASE_TIME);
return;
case ERASE_MAIN:
if (!main_range.isInRange(address)) {
return;
}
for (int i=main_range.start; i < main_range.end; i++) {
memory[i]=0xff;
}
waitFlashProcess(MASS_ERASE_TIME);
return;
case ERASE_ALL:
for (int i=main_range.start; i < main_range.end; i++) {
memory[i]=0xff;
}
for (int i=info_range.start; i < main_range.end; i++) {
memory[i]=0xff;
}
waitFlashProcess(MASS_ERASE_TIME);
return;
}
switch (current_write_mode) {
case WRITE_BLOCK:
wait=false;
if (blockwrite_count == 0) {
wait_time=BLOCKWRITE_FIRST_TIME;
if (DEBUG) {
log("String_Node_Str" + Utils.hex16(address));
}
if (addressInFlash(cpu.readRegister(MSP430.PC))) {
logw("String_Node_Str");
}
}
 else {
wait_time=BLOCKWRITE_TIME;
}
break;
case WRITE_SINGLE:
wait_time=WRITE_TIME;
break;
}
memory[address]&=data & 0xff;
if (word) {
memory[address + 1]&=(data >> 8) & 0xff;
}
if (wait_time < 0) {
throw new RuntimeException("String_Node_Str");
}
waitFlashProcess(wait_time);
}

Fixed version (ground truth):
public void flashWrite(int address,int data,boolean word){
  int wait_time=-1;
  if (locked) {
    if (DEBUG) {
      log("String_Node_Str");
    }
    return;
  }
  if (busy || wait == false) {
    if (!((mode & BLKWRT) != 0 && wait)) {
      triggerAccessViolation("String_Node_Str");
      return;
    }
  }
switch (currentWriteMode) {
case ERASE_SEGMENT:
    int a_area_start[]=new int[1];
  int a_area_end[]=new int[1];
getSegmentRange(address,a_area_start,a_area_end);
int area_start=a_area_start[0];
int area_end=a_area_end[0];
if (DEBUG) {
log("String_Node_Str" + Utils.hex16(address) + "String_Node_Str"+ Utils.hex16(area_start)+ "String_Node_Str"+ Utils.hex16(area_end));
}
for (int i=area_start; i < area_end; i++) {
memory[i]=0xff;
}
waitFlashProcess(SEGMENT_ERASE_TIME);
break;
case ERASE_MAIN:
if (!main_range.isInRange(address)) {
return;
}
for (int i=main_range.start; i < main_range.end; i++) {
memory[i]=0xff;
}
waitFlashProcess(MASS_ERASE_TIME);
break;
case ERASE_ALL:
for (int i=main_range.start; i < main_range.end; i++) {
memory[i]=0xff;
}
for (int i=info_range.start; i < main_range.end; i++) {
memory[i]=0xff;
}
waitFlashProcess(MASS_ERASE_TIME);
break;
case WRITE_SINGLE:
case WRITE_BLOCK:
if (currentWriteMode == WriteMode.WRITE_BLOCK) {
wait=false;
if (blockwriteCount == 0) {
wait_time=BLOCKWRITE_FIRST_TIME;
if (DEBUG) {
log("String_Node_Str" + Utils.hex16(address));
}
if (addressInFlash(cpu.readRegister(MSP430.PC))) {
logw("String_Node_Str");
}
}
 else {
wait_time=BLOCKWRITE_TIME;
}
}
 else {
wait_time=WRITE_TIME;
}
memory[address]&=data & 0xff;
if (word) {
memory[address + 1]&=(data >> 8) & 0xff;
}
if (DEBUG) {
log("String_Node_Str" + data + "String_Node_Str"+ Utils.hex16(address));
}
waitFlashProcess(wait_time);
break;
}
}