Program: 5647
Project: 5647
Buggy source:
/** 
 * \brief check whether the 112-bit group-id of the multicast address is mappable to a 9-bit group-id It is true if the group is the all nodes or all routers group.
 */
public byte[] generatePacketData(IPv6Packet packet){
  int enc1=0, enc2=0;
  byte[] data=new byte[40];
  int pos=2;
  if (packet.flowLabel == 0) {
    enc1|=IPHC_VF_C;
  }
  if (packet.trafficClass == 0) {
    enc1|=IPHC_TC_C;
  }
  if ((enc1 & IPHC_VF_C) == 0) {
    pos+=packet.writeVFlow(data,pos);
  }
  if ((enc1 & IPHC_TC_C) == 0) {
    data[pos++]=(byte)(packet.trafficClass & 0xff);
  }
  data[pos++]=(byte)(packet.nextHeader & 0xff);
switch (packet.hopLimit) {
case 1:
    enc1|=IPHC_TTL_1;
  break;
case 64:
enc1|=IPHC_TTL_64;
break;
case 255:
enc1|=IPHC_TTL_255;
break;
default :
data[pos++]=(byte)(packet.hopLimit & 0xff);
}
int context;
if ((context=lookupContext(packet.sourceAddress)) != -1) {
enc2|=context << 4;
if (packet.isSourceMACBased()) {
enc2|=IPHC_SAM_0;
}
 else if (is16bitCompressable(packet.sourceAddress)) {
enc2|=IPHC_SAM_16;
data[pos++]=packet.sourceAddress[14];
data[pos++]=packet.sourceAddress[15];
}
 else {
enc2|=IPHC_SAM_64;
System.arraycopy(packet.sourceAddress,8,data,pos,8);
pos+=8;
}
}
 else {
enc2|=IPHC_SAM_I;
System.arraycopy(packet.sourceAddress,0,data,pos,16);
pos+=16;
}
if (packet.isMulticastDestination()) {
if (isMulticastCompressable(packet.destAddress)) {
enc2|=IPHC_DAM_16;
data[pos]=(byte)IPHC_MCAST_RANGE;
data[pos++]|=(packet.destAddress[1] & 0x0F) << 1;
data[pos++]=packet.destAddress[15];
}
 else {
enc2|=IPHC_DAM_I;
System.arraycopy(packet.destAddress,0,data,pos,16);
pos+=16;
}
}
 else {
if ((context=lookupContext(packet.destAddress)) != -1) {
enc2|=context;
if (packet.isDestinationMACBased()) {
enc2|=IPHC_DAM_0;
}
 else {
if (is16bitCompressable(packet.destAddress)) {
enc2|=IPHC_DAM_16;
data[pos++]=packet.destAddress[14];
data[pos++]=packet.destAddress[15];
}
 else {
enc2|=IPHC_DAM_64;
System.arraycopy(packet.destAddress,8,data,pos,8);
pos+=8;
}
}
}
 else {
if (DEBUG) System.out.println("String_Node_Str");
enc2|=IPHC_DAM_I;
System.arraycopy(packet.destAddress,0,data,pos,16);
pos+=16;
}
}
data[0]=(byte)(enc1 & 0xff);
data[1]=(byte)(enc2 & 0xff);
if (DEBUG) System.out.println("String_Node_Str" + pos + "String_Node_Str"+ Utils.hex8(enc1)+ "String_Node_Str"+ Utils.hex8(enc2));
if (DEBUG) {
System.out.print("String_Node_Str");
IPv6Packet.printAddress(System.out,packet.sourceAddress);
System.out.print("String_Node_Str");
IPv6Packet.printAddress(System.out,packet.destAddress);
}
IPPayload payload=packet.getIPPayload();
byte[] pload=payload.generatePacketData(packet);
if (DEBUG) System.out.println("String_Node_Str" + pload.length);
byte[] dataPacket=new byte[pos + pload.length];
System.arraycopy(data,0,dataPacket,0,pos);
System.arraycopy(pload,0,dataPacket,pos,pload.length);
return dataPacket;
}

Fixed version (ground truth):
/** 
 * \brief check whether the 112-bit group-id of the multicast address is mappable to a 9-bit group-id It is true if the group is the all nodes or all routers group.
 */
public byte[] generatePacketData(IPv6Packet packet){
  int enc1=0, enc2=0;
  byte[] data=new byte[40];
  int pos=2;
  if (packet.flowLabel == 0) {
    enc1|=IPHC_VF_C;
  }
  if (packet.trafficClass == 0) {
    enc1|=IPHC_TC_C;
  }
  if ((enc1 & IPHC_VF_C) == 0) {
    pos+=packet.writeVFlow(data,pos);
  }
  if ((enc1 & IPHC_TC_C) == 0) {
    data[pos++]=(byte)(packet.trafficClass & 0xff);
  }
  data[pos++]=(byte)(packet.nextHeader & 0xff);
switch (packet.hopLimit) {
case 1:
    enc1|=IPHC_TTL_1;
  break;
case 64:
enc1|=IPHC_TTL_64;
break;
case 255:
enc1|=IPHC_TTL_255;
break;
default :
data[pos++]=(byte)(packet.hopLimit & 0xff);
}
int context;
if ((context=lookupContext(packet.sourceAddress)) != -1) {
if (DEBUG) System.out.println("String_Node_Str" + context);
enc2|=context << 4;
if (packet.isSourceMACBased()) {
enc2|=IPHC_SAM_0;
}
 else if (is16bitCompressable(packet.sourceAddress)) {
enc2|=IPHC_SAM_16;
data[pos++]=packet.sourceAddress[14];
data[pos++]=packet.sourceAddress[15];
}
 else {
enc2|=IPHC_SAM_64;
System.arraycopy(packet.sourceAddress,8,data,pos,8);
pos+=8;
}
}
 else {
if (DEBUG) System.out.println("String_Node_Str");
enc2|=IPHC_SAM_I;
System.arraycopy(packet.sourceAddress,0,data,pos,16);
pos+=16;
}
if (packet.isMulticastDestination()) {
if (isMulticastCompressable(packet.destAddress)) {
enc2|=IPHC_DAM_16;
data[pos]=(byte)IPHC_MCAST_RANGE;
data[pos++]|=(packet.destAddress[1] & 0x0F) << 1;
data[pos++]=packet.destAddress[15];
}
 else {
enc2|=IPHC_DAM_I;
System.arraycopy(packet.destAddress,0,data,pos,16);
pos+=16;
}
}
 else {
if ((context=lookupContext(packet.destAddress)) != -1) {
if (DEBUG) System.out.println("String_Node_Str" + context);
enc2|=context;
if (packet.isDestinationMACBased()) {
enc2|=IPHC_DAM_0;
}
 else {
if (is16bitCompressable(packet.destAddress)) {
enc2|=IPHC_DAM_16;
data[pos++]=packet.destAddress[14];
data[pos++]=packet.destAddress[15];
}
 else {
enc2|=IPHC_DAM_64;
System.arraycopy(packet.destAddress,8,data,pos,8);
pos+=8;
}
}
}
 else {
if (DEBUG) System.out.println("String_Node_Str");
enc2|=IPHC_DAM_I;
System.arraycopy(packet.destAddress,0,data,pos,16);
pos+=16;
}
}
data[0]=(byte)(enc1 & 0xff);
data[1]=(byte)(enc2 & 0xff);
if (DEBUG) System.out.println("String_Node_Str" + pos + "String_Node_Str"+ Utils.hex8(enc1)+ "String_Node_Str"+ Utils.hex8(enc2));
if (DEBUG) {
System.out.print("String_Node_Str");
IPv6Packet.printAddress(System.out,packet.sourceAddress);
System.out.print("String_Node_Str");
IPv6Packet.printAddress(System.out,packet.destAddress);
}
IPPayload payload=packet.getIPPayload();
byte[] pload=payload.generatePacketData(packet);
if (DEBUG) System.out.println("String_Node_Str" + pload.length);
byte[] dataPacket=new byte[pos + pload.length];
System.arraycopy(data,0,dataPacket,0,pos);
System.arraycopy(pload,0,dataPacket,pos,pload.length);
return dataPacket;
}