Program: 58374
Project: 58374
Buggy source:
private boolean qr_binary(int version,int target_binlen,int est_binlen){
  int position=0;
  int short_data_block_length, i, scheme=1;
  int padbits;
  int current_binlen, current_bytes;
  int toggle;
  boolean alphanumPercent;
  String oneChar;
  qrMode data_block;
  int jis;
  byte[] jisBytes;
  int msb, lsb, prod;
  int count, first, second, third;
  int weight;
  binary="String_Node_Str";
  if ((eciMode != 3) && (eciMode != 20)) {
    binary+="String_Node_Str";
    if ((eciMode >= 0) && (eciMode <= 127)) {
      binary+="String_Node_Str";
      qr_bscan(eciMode,0x40);
    }
    if ((eciMode >= 128) && (eciMode <= 16383)) {
      binary+="String_Node_Str";
      qr_bscan(eciMode,0x1000);
    }
    if ((eciMode >= 16384) && (eciMode <= 999999)) {
      binary+="String_Node_Str";
      qr_bscan(eciMode,0x100000);
    }
  }
  if (inputDataType == DataType.GS1) {
    binary+="String_Node_Str";
  }
  if (version <= 9) {
    scheme=1;
  }
 else   if ((version >= 10) && (version <= 26)) {
    scheme=2;
  }
 else   if (version >= 27) {
    scheme=3;
  }
  if (debug) {
    System.out.printf("String_Node_Str");
  }
  alphanumPercent=false;
  do {
    data_block=inputMode[position];
    short_data_block_length=0;
    do {
      short_data_block_length++;
    }
 while (((short_data_block_length + position) < inputLength) && (inputMode[position + short_data_block_length] == data_block));
switch (data_block) {
case KANJI:
      binary+="String_Node_Str";
    qr_bscan(short_data_block_length,0x20 << (scheme * 2));
  if (debug) {
    System.out.printf("String_Node_Str");
  }
for (i=0; i < short_data_block_length; i++) {
  oneChar="String_Node_Str";
  oneChar+=(char)inputData[position + i];
  try {
    jisBytes=oneChar.getBytes("String_Node_Str");
  }
 catch (  UnsupportedEncodingException e) {
    error_msg="String_Node_Str";
    return false;
  }
  jis=((jisBytes[0] & 0xFF) << 8) + (jisBytes[1] & 0xFF);
  if (jis > 0x9fff) {
    jis-=0xc140;
  }
 else {
    jis-=0x8140;
  }
  msb=(jis & 0xff00) >> 8;
  lsb=(jis & 0xff);
  prod=(msb * 0xc0) + lsb;
  qr_bscan(prod,0x1000);
  if (debug) {
    System.out.printf("String_Node_Str",prod);
  }
}
break;
case BINARY:
binary+="String_Node_Str";
qr_bscan(short_data_block_length,scheme > 1 ? 0x8000 : 0x80);
if (debug) {
System.out.printf("String_Node_Str");
}
for (i=0; i < short_data_block_length; i++) {
int lbyte=(int)(inputData[position + i] & 0xFF);
if ((inputDataType == DataType.GS1) && (lbyte == '[')) {
lbyte=0x1d;
}
qr_bscan(lbyte,0x80);
if (debug) {
System.out.printf("String_Node_Str",lbyte);
}
}
break;
case ALPHANUM:
binary+="String_Node_Str";
qr_bscan(short_data_block_length,0x40 << (2 * scheme));
if (debug) {
System.out.printf("String_Node_Str");
}
i=0;
while (i < short_data_block_length) {
if (!alphanumPercent) {
if ((inputDataType == DataType.GS1) && (inputData[position + i] == '%')) {
first=positionOf('%',rhodium);
second=positionOf('%',rhodium);
count=2;
prod=(first * 45) + second;
i++;
}
 else {
if ((inputDataType == DataType.GS1) && (inputData[position + i] == '[')) {
first=positionOf('%',rhodium);
}
 else {
first=positionOf((char)(inputData[position + i] & 0xFF),rhodium);
}
count=1;
i++;
prod=first;
if (i < short_data_block_length) {
if (inputMode[position + i] == qrMode.ALPHANUM) {
if ((inputDataType == DataType.GS1) && (inputData[position + i] == '%')) {
second=positionOf('%',rhodium);
count=2;
prod=(first * 45) + second;
alphanumPercent=true;
}
 else {
if ((inputDataType == DataType.GS1) && (inputData[position + i] == '[')) {
second=positionOf('%',rhodium);
}
 else {
second=positionOf((char)(inputData[position + i] & 0xFF),rhodium);
}
count=2;
i++;
prod=(first * 45) + second;
}
}
}
}
}
 else {
first=positionOf('%',rhodium);
count=1;
i++;
prod=first;
alphanumPercent=false;
if (i < short_data_block_length) {
if (inputMode[position + i] == qrMode.ALPHANUM) {
if ((inputDataType == DataType.GS1) && (inputData[position + i] == '%')) {
second=positionOf('%',rhodium);
count=2;
prod=(first * 45) + second;
alphanumPercent=true;
}
 else {
if ((inputDataType == DataType.GS1) && (inputData[position + i] == '[')) {
second=positionOf('%',rhodium);
}
 else {
second=positionOf((char)(inputData[position + i] & 0xFF),rhodium);
}
count=2;
i++;
prod=(first * 45) + second;
}
}
}
}
qr_bscan(prod,count == 2 ? 0x400 : 0x20);
if (debug) {
System.out.printf("String_Node_Str",prod);
}
}
;
break;
case NUMERIC:
binary+="String_Node_Str";
qr_bscan(short_data_block_length,0x80 << (2 * scheme));
if (debug) {
System.out.printf("String_Node_Str");
}
i=0;
while (i < short_data_block_length) {
first=Character.getNumericValue(inputData[position + i]);
count=1;
prod=first;
if ((i + 1) < short_data_block_length) {
second=Character.getNumericValue(inputData[position + i + 1]);
count=2;
prod=(prod * 10) + second;
}
if ((i + 2) < short_data_block_length) {
third=Character.getNumericValue(inputData[position + i + 2]);
count=3;
prod=(prod * 10) + third;
}
qr_bscan(prod,1 << (3 * count));
if (debug) {
System.out.printf("String_Node_Str",prod);
}
i+=count;
}
;
break;
}
position+=short_data_block_length;
}
 while (position < inputLength);
if (debug) {
System.out.printf("String_Node_Str");
}
binary+="String_Node_Str";
current_binlen=binary.length();
padbits=8 - (current_binlen % 8);
if (padbits == 8) {
padbits=0;
}
current_bytes=(current_binlen + padbits) / 8;
for (i=0; i < padbits; i++) {
binary+="String_Node_Str";
}
for (i=0; i < current_bytes; i++) {
datastream[i]=0x00;
for (weight=0; weight < 8; weight++) {
if (binary.charAt((i * 8) + weight) == '1') {
datastream[i]+=(0x80 >> weight);
}
}
}
toggle=0;
for (i=current_bytes; i < target_binlen; i++) {
if (toggle == 0) {
datastream[i]=0xec;
toggle=1;
}
 else {
datastream[i]=0x11;
toggle=0;
}
}
if (debug) {
System.out.printf("String_Node_Str");
for (i=0; i < target_binlen; i++) {
System.out.printf("String_Node_Str",datastream[i]);
}
System.out.printf("String_Node_Str");
}
return true;
}

Fixed version (ground truth):
private boolean qr_binary(int version,int target_binlen){
  int position=0;
  int short_data_block_length, i, scheme=1;
  int padbits;
  int current_binlen, current_bytes;
  int toggle;
  boolean alphanumPercent;
  String oneChar;
  qrMode data_block;
  int jis;
  byte[] jisBytes;
  int msb, lsb, prod;
  int count, first, second, third;
  int weight;
  binary="String_Node_Str";
  if ((eciMode != 3) && (eciMode != 20)) {
    binary+="String_Node_Str";
    if ((eciMode >= 0) && (eciMode <= 127)) {
      binary+="String_Node_Str";
      qr_bscan(eciMode,0x40);
    }
    if ((eciMode >= 128) && (eciMode <= 16383)) {
      binary+="String_Node_Str";
      qr_bscan(eciMode,0x1000);
    }
    if ((eciMode >= 16384) && (eciMode <= 999999)) {
      binary+="String_Node_Str";
      qr_bscan(eciMode,0x100000);
    }
  }
  if (inputDataType == DataType.GS1) {
    binary+="String_Node_Str";
  }
  if (version <= 9) {
    scheme=1;
  }
 else   if ((version >= 10) && (version <= 26)) {
    scheme=2;
  }
 else   if (version >= 27) {
    scheme=3;
  }
  if (debug) {
    System.out.printf("String_Node_Str");
  }
  alphanumPercent=false;
  do {
    data_block=inputMode[position];
    short_data_block_length=0;
    do {
      short_data_block_length++;
    }
 while (((short_data_block_length + position) < inputLength) && (inputMode[position + short_data_block_length] == data_block));
switch (data_block) {
case KANJI:
      binary+="String_Node_Str";
    qr_bscan(short_data_block_length,0x20 << (scheme * 2));
  if (debug) {
    System.out.printf("String_Node_Str");
  }
for (i=0; i < short_data_block_length; i++) {
  oneChar="String_Node_Str";
  oneChar+=(char)inputData[position + i];
  try {
    jisBytes=oneChar.getBytes("String_Node_Str");
  }
 catch (  UnsupportedEncodingException e) {
    error_msg="String_Node_Str";
    return false;
  }
  jis=((jisBytes[0] & 0xFF) << 8) + (jisBytes[1] & 0xFF);
  if (jis > 0x9fff) {
    jis-=0xc140;
  }
 else {
    jis-=0x8140;
  }
  msb=(jis & 0xff00) >> 8;
  lsb=(jis & 0xff);
  prod=(msb * 0xc0) + lsb;
  qr_bscan(prod,0x1000);
  if (debug) {
    System.out.printf("String_Node_Str",prod);
  }
}
break;
case BINARY:
binary+="String_Node_Str";
qr_bscan(short_data_block_length,scheme > 1 ? 0x8000 : 0x80);
if (debug) {
System.out.printf("String_Node_Str");
}
for (i=0; i < short_data_block_length; i++) {
int lbyte=(int)(inputData[position + i] & 0xFF);
if ((inputDataType == DataType.GS1) && (lbyte == '[')) {
lbyte=0x1d;
}
qr_bscan(lbyte,0x80);
if (debug) {
System.out.printf("String_Node_Str",lbyte);
}
}
break;
case ALPHANUM:
binary+="String_Node_Str";
qr_bscan(short_data_block_length,0x40 << (2 * scheme));
if (debug) {
System.out.printf("String_Node_Str");
}
i=0;
while (i < short_data_block_length) {
if (!alphanumPercent) {
if ((inputDataType == DataType.GS1) && (inputData[position + i] == '%')) {
first=positionOf('%',rhodium);
second=positionOf('%',rhodium);
count=2;
prod=(first * 45) + second;
i++;
}
 else {
if ((inputDataType == DataType.GS1) && (inputData[position + i] == '[')) {
first=positionOf('%',rhodium);
}
 else {
first=positionOf((char)(inputData[position + i] & 0xFF),rhodium);
}
count=1;
i++;
prod=first;
if (i < short_data_block_length) {
if (inputMode[position + i] == qrMode.ALPHANUM) {
if ((inputDataType == DataType.GS1) && (inputData[position + i] == '%')) {
second=positionOf('%',rhodium);
count=2;
prod=(first * 45) + second;
alphanumPercent=true;
}
 else {
if ((inputDataType == DataType.GS1) && (inputData[position + i] == '[')) {
second=positionOf('%',rhodium);
}
 else {
second=positionOf((char)(inputData[position + i] & 0xFF),rhodium);
}
count=2;
i++;
prod=(first * 45) + second;
}
}
}
}
}
 else {
first=positionOf('%',rhodium);
count=1;
i++;
prod=first;
alphanumPercent=false;
if (i < short_data_block_length) {
if (inputMode[position + i] == qrMode.ALPHANUM) {
if ((inputDataType == DataType.GS1) && (inputData[position + i] == '%')) {
second=positionOf('%',rhodium);
count=2;
prod=(first * 45) + second;
alphanumPercent=true;
}
 else {
if ((inputDataType == DataType.GS1) && (inputData[position + i] == '[')) {
second=positionOf('%',rhodium);
}
 else {
second=positionOf((char)(inputData[position + i] & 0xFF),rhodium);
}
count=2;
i++;
prod=(first * 45) + second;
}
}
}
}
qr_bscan(prod,count == 2 ? 0x400 : 0x20);
if (debug) {
System.out.printf("String_Node_Str",prod);
}
}
;
break;
case NUMERIC:
binary+="String_Node_Str";
qr_bscan(short_data_block_length,0x80 << (2 * scheme));
if (debug) {
System.out.printf("String_Node_Str");
}
i=0;
while (i < short_data_block_length) {
first=Character.getNumericValue(inputData[position + i]);
count=1;
prod=first;
if ((i + 1) < short_data_block_length) {
second=Character.getNumericValue(inputData[position + i + 1]);
count=2;
prod=(prod * 10) + second;
}
if ((i + 2) < short_data_block_length) {
third=Character.getNumericValue(inputData[position + i + 2]);
count=3;
prod=(prod * 10) + third;
}
qr_bscan(prod,1 << (3 * count));
if (debug) {
System.out.printf("String_Node_Str",prod);
}
i+=count;
}
;
break;
}
position+=short_data_block_length;
}
 while (position < inputLength);
if (debug) {
System.out.printf("String_Node_Str");
}
binary+="String_Node_Str";
current_binlen=binary.length();
padbits=8 - (current_binlen % 8);
if (padbits == 8) {
padbits=0;
}
current_bytes=(current_binlen + padbits) / 8;
for (i=0; i < padbits; i++) {
binary+="String_Node_Str";
}
for (i=0; i < current_bytes; i++) {
datastream[i]=0x00;
for (weight=0; weight < 8; weight++) {
if (binary.charAt((i * 8) + weight) == '1') {
datastream[i]+=(0x80 >> weight);
}
}
}
toggle=0;
for (i=current_bytes; i < target_binlen; i++) {
if (toggle == 0) {
datastream[i]=0xec;
toggle=1;
}
 else {
datastream[i]=0x11;
toggle=0;
}
}
if (debug) {
System.out.printf("String_Node_Str");
for (i=0; i < target_binlen; i++) {
System.out.printf("String_Node_Str",datastream[i]);
}
System.out.printf("String_Node_Str");
}
return true;
}