Program: 135830
Project: 135830
Buggy source:
/** 
 * Insert in the data buffer at position dictated by the offset the number of bits specified from the input data byte array. The input byte array has the bits stored starting from the LSB
 * @param byte[] data
 * @param byte[] inputdata
 * @param int    startOffset
 * @param int    numBits
 */
public static void insertBits(byte[] data,byte[] inputdataLSB,int startOffset,int numBits){
  byte[] inputdata=shiftBitsToMSB(inputdataLSB,numBits);
  int numBytes=numBits / NetUtils.NumBitsInAByte;
  int startByteOffset=startOffset / NetUtils.NumBitsInAByte;
  int extraOffsetBits=startOffset % NetUtils.NumBitsInAByte;
  int extranumBits=numBits % NetUtils.NumBitsInAByte;
  int RestBits=numBits % NetUtils.NumBitsInAByte;
  int InputMSBbits=0, InputLSBbits=0;
  int i;
  if (numBits == 0) {
    return;
  }
  if (extraOffsetBits == 0) {
    if (extranumBits == 0) {
      numBytes=numBits / NetUtils.NumBitsInAByte;
      System.arraycopy(inputdata,0,data,startByteOffset,numBytes);
    }
 else {
      System.arraycopy(inputdata,0,data,startByteOffset,numBytes);
      data[startByteOffset + numBytes]=(byte)(data[startByteOffset + numBytes] | (inputdata[numBytes] & getMSBMask(extranumBits)));
    }
  }
 else {
    for (i=0; i < numBytes; i++) {
      if (i != 0)       InputLSBbits=(inputdata[i - 1] & getLSBMask(extraOffsetBits));
      InputMSBbits=(byte)(inputdata[i] & (getMSBMask(NetUtils.NumBitsInAByte - extraOffsetBits)));
      InputMSBbits=(InputMSBbits >= 0) ? InputMSBbits : InputMSBbits + 256;
      data[startByteOffset + i]=(byte)(data[startByteOffset + i] | (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)) | (InputMSBbits >> extraOffsetBits));
      InputMSBbits=InputLSBbits=0;
    }
    if (RestBits < (NetUtils.NumBitsInAByte - extraOffsetBits)) {
      if (numBytes != 0)       InputLSBbits=(inputdata[i - 1] & getLSBMask(extraOffsetBits));
      InputMSBbits=(byte)(inputdata[i] & (getMSBMask(RestBits)));
      InputMSBbits=(InputMSBbits >= 0) ? InputMSBbits : InputMSBbits + 256;
      data[startByteOffset + i]=(byte)((data[startByteOffset + i]) | (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)) | (InputMSBbits >> extraOffsetBits));
    }
 else     if (RestBits == (NetUtils.NumBitsInAByte - extraOffsetBits)) {
      if (numBytes != 0)       InputLSBbits=(inputdata[i - 1] & getLSBMask(extraOffsetBits));
      InputMSBbits=(byte)(inputdata[i] & (getMSBMask(NetUtils.NumBitsInAByte - extraOffsetBits)));
      InputMSBbits=(InputMSBbits >= 0) ? InputMSBbits : InputMSBbits + 256;
      data[startByteOffset + i]=(byte)(data[startByteOffset + i] | (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)) | (InputMSBbits >> extraOffsetBits));
    }
 else {
      if (numBytes != 0)       InputLSBbits=(inputdata[i - 1] & getLSBMask(extraOffsetBits));
      InputMSBbits=(byte)(inputdata[i] & (getMSBMask(NetUtils.NumBitsInAByte - extraOffsetBits)));
      InputMSBbits=(InputMSBbits >= 0) ? InputMSBbits : InputMSBbits + 256;
      data[startByteOffset + i]=(byte)(data[startByteOffset + i] | (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)) | (InputMSBbits >> extraOffsetBits));
      InputLSBbits=(inputdata[i] & (getLSBMask(RestBits - (NetUtils.NumBitsInAByte - extraOffsetBits)) << (NetUtils.NumBitsInAByte - RestBits)));
      data[startByteOffset + i + 1]=(byte)(data[startByteOffset + i + 1] | (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)));
    }
  }
}

Fixed version (ground truth):
/** 
 * Insert in the data buffer at position dictated by the offset the number of bits specified from the input data byte array. The input byte array has the bits stored starting from the LSB
 * @param data
 * @param inputdataLSB
 * @param startOffset
 * @param numBits
 */
public static void insertBits(byte[] data,byte[] inputdataLSB,int startOffset,int numBits){
  byte[] inputdata=shiftBitsToMSB(inputdataLSB,numBits);
  int numBytes=numBits / NetUtils.NumBitsInAByte;
  int startByteOffset=startOffset / NetUtils.NumBitsInAByte;
  int extraOffsetBits=startOffset % NetUtils.NumBitsInAByte;
  int extranumBits=numBits % NetUtils.NumBitsInAByte;
  int RestBits=numBits % NetUtils.NumBitsInAByte;
  int InputMSBbits=0, InputLSBbits=0;
  int i;
  if (numBits == 0) {
    return;
  }
  if (extraOffsetBits == 0) {
    if (extranumBits == 0) {
      numBytes=numBits / NetUtils.NumBitsInAByte;
      System.arraycopy(inputdata,0,data,startByteOffset,numBytes);
    }
 else {
      System.arraycopy(inputdata,0,data,startByteOffset,numBytes);
      data[startByteOffset + numBytes]=(byte)(data[startByteOffset + numBytes] | (inputdata[numBytes] & getMSBMask(extranumBits)));
    }
  }
 else {
    for (i=0; i < numBytes; i++) {
      if (i != 0)       InputLSBbits=(inputdata[i - 1] & getLSBMask(extraOffsetBits));
      InputMSBbits=(byte)(inputdata[i] & (getMSBMask(NetUtils.NumBitsInAByte - extraOffsetBits)));
      InputMSBbits=(InputMSBbits >= 0) ? InputMSBbits : InputMSBbits + 256;
      data[startByteOffset + i]=(byte)(data[startByteOffset + i] | (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)) | (InputMSBbits >> extraOffsetBits));
      InputMSBbits=InputLSBbits=0;
    }
    if (RestBits < (NetUtils.NumBitsInAByte - extraOffsetBits)) {
      if (numBytes != 0)       InputLSBbits=(inputdata[i - 1] & getLSBMask(extraOffsetBits));
      InputMSBbits=(byte)(inputdata[i] & (getMSBMask(RestBits)));
      InputMSBbits=(InputMSBbits >= 0) ? InputMSBbits : InputMSBbits + 256;
      data[startByteOffset + i]=(byte)((data[startByteOffset + i]) | (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)) | (InputMSBbits >> extraOffsetBits));
    }
 else     if (RestBits == (NetUtils.NumBitsInAByte - extraOffsetBits)) {
      if (numBytes != 0)       InputLSBbits=(inputdata[i - 1] & getLSBMask(extraOffsetBits));
      InputMSBbits=(byte)(inputdata[i] & (getMSBMask(NetUtils.NumBitsInAByte - extraOffsetBits)));
      InputMSBbits=(InputMSBbits >= 0) ? InputMSBbits : InputMSBbits + 256;
      data[startByteOffset + i]=(byte)(data[startByteOffset + i] | (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)) | (InputMSBbits >> extraOffsetBits));
    }
 else {
      if (numBytes != 0)       InputLSBbits=(inputdata[i - 1] & getLSBMask(extraOffsetBits));
      InputMSBbits=(byte)(inputdata[i] & (getMSBMask(NetUtils.NumBitsInAByte - extraOffsetBits)));
      InputMSBbits=(InputMSBbits >= 0) ? InputMSBbits : InputMSBbits + 256;
      data[startByteOffset + i]=(byte)(data[startByteOffset + i] | (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)) | (InputMSBbits >> extraOffsetBits));
      InputLSBbits=(inputdata[i] & (getLSBMask(RestBits - (NetUtils.NumBitsInAByte - extraOffsetBits)) << (NetUtils.NumBitsInAByte - RestBits)));
      data[startByteOffset + i + 1]=(byte)(data[startByteOffset + i + 1] | (InputLSBbits << (NetUtils.NumBitsInAByte - extraOffsetBits)));
    }
  }
}