Program: 5609
Project: 5609
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 + 8];
  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+=writeVFlow(packet,data,pos);
  }
  if ((enc1 & IPHC_TC_C) == 0) {
    data[pos++]=(byte)(packet.trafficClass & 0xff);
  }
  if (packet.nextHeader == UDPPacket.DISPATCH) {
    enc1|=IPHC_NH_C;
  }
 else {
    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;
}
IPv6Packet.printAddress(System.out,packet.destAddress);
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;
}
}
if (packet.nextHeader == UDPPacket.DISPATCH) {
UDPPacket udp=(UDPPacket)packet.getIPPayload();
if (udp.sourcePort >= UDP_PORT_MIN && udp.sourcePort < UDP_PORT_MAX && udp.destinationPort >= UDP_PORT_MIN && udp.destinationPort < UDP_PORT_MAX) {
data[pos++]=(byte)NHC_UDP_C;
data[pos++]=(byte)(((udp.sourcePort - UDP_PORT_MIN) << 4) + (udp.destinationPort - UDP_PORT_MIN));
int checksum=udp.doVirtualChecksum(packet);
data[pos++]=(byte)(checksum >> 8);
data[pos++]=(byte)(checksum & 0xff);
}
 else {
data[pos++]=(byte)NHC_UDP_I;
data[pos++]=(byte)(udp.sourcePort >> 8);
data[pos++]=(byte)(udp.sourcePort & 0xff);
data[pos++]=(byte)(udp.destinationPort >> 8);
data[pos++]=(byte)(udp.destinationPort & 0xff);
int checksum=udp.doVirtualChecksum(packet);
data[pos++]=(byte)(checksum >> 8);
data[pos++]=(byte)(checksum & 0xff);
}
}
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);
}
byte[] pload;
if (packet.nextHeader == UDPPacket.DISPATCH) {
UDPPacket udp=(UDPPacket)packet.getIPPayload();
pload=udp.payload;
}
 else {
IPPayload payload=packet.getIPPayload();
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 + 8];
  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+=writeVFlow(packet,data,pos);
  }
  if ((enc1 & IPHC_TC_C) == 0) {
    data[pos++]=(byte)(packet.trafficClass & 0xff);
  }
  if (packet.nextHeader == UDPPacket.DISPATCH) {
    enc1|=IPHC_NH_C;
  }
 else {
    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;
}
}
if (packet.nextHeader == UDPPacket.DISPATCH) {
UDPPacket udp=(UDPPacket)packet.getIPPayload();
if (udp.sourcePort >= UDP_PORT_MIN && udp.sourcePort < UDP_PORT_MAX && udp.destinationPort >= UDP_PORT_MIN && udp.destinationPort < UDP_PORT_MAX) {
data[pos++]=(byte)NHC_UDP_C;
data[pos++]=(byte)(((udp.sourcePort - UDP_PORT_MIN) << 4) + (udp.destinationPort - UDP_PORT_MIN));
int checksum=udp.doVirtualChecksum(packet);
data[pos++]=(byte)(checksum >> 8);
data[pos++]=(byte)(checksum & 0xff);
}
 else {
data[pos++]=(byte)NHC_UDP_I;
data[pos++]=(byte)(udp.sourcePort >> 8);
data[pos++]=(byte)(udp.sourcePort & 0xff);
data[pos++]=(byte)(udp.destinationPort >> 8);
data[pos++]=(byte)(udp.destinationPort & 0xff);
int checksum=udp.doVirtualChecksum(packet);
data[pos++]=(byte)(checksum >> 8);
data[pos++]=(byte)(checksum & 0xff);
}
}
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);
}
byte[] pload;
if (packet.nextHeader == UDPPacket.DISPATCH) {
UDPPacket udp=(UDPPacket)packet.getIPPayload();
pload=udp.payload;
}
 else {
IPPayload payload=packet.getIPPayload();
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;
}