Program: 53269
Project: 53269
Buggy source:
public byte[][] splitToFrames(java.nio.ByteBuffer packet,int blockIndex,int[] index,int count,Command cmd,int resultChoice){
  ByteArrayOutputStream tmp=new ByteArrayOutputStream();
  if (this.getInterfaceType() == InterfaceType.GENERAL && !(Ciphering.getSecurity() != Security.NONE && frameSequence != -1)) {
    try {
      if (getServer()) {
        tmp.write(GXCommon.LLCReplyBytes);
      }
 else {
        tmp.write(GXCommon.LLCSendBytes);
      }
    }
 catch (    Exception ex) {
      throw new RuntimeException(ex.getMessage());
    }
  }
  if (cmd != Command.None && this.getUseLogicalNameReferencing()) {
    boolean moreBlocks=packet.limit() > getMaxReceivePDUSize() && packet.limit() > index[0] + count;
    tmp.write(cmd.getValue());
    tmp.write((byte)(moreBlocks ? 2 : 1));
    tmp.write(getInvokeIDPriority());
    if (getServer()) {
      tmp.write(resultChoice);
    }
    if (moreBlocks) {
      tmp.write((byte)blockIndex >> 8);
      tmp.write((byte)blockIndex & 0xFF);
      tmp.write((byte)0);
      GXCommon.setObjectCount(count,tmp);
    }
  }
 else   if (cmd != Command.None && !this.getUseLogicalNameReferencing()) {
    tmp.write((byte)cmd.getValue());
  }
  if (Ciphering.getSecurity() != Security.NONE && frameSequence != -1) {
    try {
      int cnt=count;
      if (count + index[0] > packet.limit()) {
        cnt=packet.limit() - index[0];
      }
      tmp.write(packet.array(),index[0],cnt);
    }
 catch (    Exception ex) {
      throw new RuntimeException(ex.getMessage());
    }
    packet.clear();
    Ciphering.setFrameCounter(Ciphering.getFrameCounter() + 1);
    Command gloCmd;
    if (cmd == Command.ReadRequest || cmd == Command.GetRequest) {
      gloCmd=Command.GloGetRequest;
    }
 else     if (cmd == Command.WriteRequest || cmd == Command.SetRequest) {
      gloCmd=Command.GloSetRequest;
    }
 else     if (cmd == Command.MethodRequest) {
      gloCmd=Command.GloMethodRequest;
    }
 else     if (cmd == Command.ReadResponse || cmd == Command.GetResponse) {
      gloCmd=Command.GloGetResponse;
    }
 else     if (cmd == Command.WriteResponse || cmd == Command.SetResponse) {
      gloCmd=Command.GloSetResponse;
    }
 else     if (cmd == Command.MethodResponse) {
      gloCmd=Command.GloMethodResponse;
    }
 else {
      throw new GXDLMSException("String_Node_Str");
    }
    byte[] tmp2=tmp.toByteArray();
    packet=java.nio.ByteBuffer.wrap(GXDLMSChippering.EncryptAesGcm(gloCmd,Ciphering.getSecurity(),Ciphering.getFrameCounter(),Ciphering.getSystemTitle(),Ciphering.getBlockCipherKey(),Ciphering.getAuthenticationKey(),tmp2));
    packet.position(packet.limit());
    count=packet.position();
    tmp.reset();
    try {
      if (this.getInterfaceType() == InterfaceType.GENERAL) {
        if (getServer()) {
          tmp.write(GXCommon.LLCReplyBytes);
        }
 else {
          tmp.write(GXCommon.LLCSendBytes);
        }
      }
    }
 catch (    Exception ex) {
      throw new RuntimeException(ex.getMessage());
    }
  }
  int dataSize;
  if (this.getInterfaceType() == InterfaceType.NET) {
    dataSize=getMaxReceivePDUSize();
  }
 else {
    if (cmd == Command.GetRequest || cmd == Command.MethodRequest || cmd == Command.ReadRequest || cmd == Command.SetRequest || cmd == Command.WriteRequest) {
      dataSize=GXCommon.intValue(getLimits().getMaxInfoTX());
    }
 else {
      dataSize=GXCommon.intValue(getLimits().getMaxInfoRX());
    }
  }
  if (count + index[0] > packet.limit()) {
    count=packet.limit() - index[0];
  }
  packet.position(index[0]);
  byte[] tmp2=new byte[count];
  packet.get(tmp2);
  try {
    tmp.write(tmp2);
  }
 catch (  Exception ex) {
    throw new RuntimeException(ex.getMessage());
  }
  index[0]+=count;
  count=tmp.size();
  if (count < dataSize) {
    dataSize=count;
  }
  int cnt=(int)(count / dataSize);
  if (count % dataSize != 0) {
    ++cnt;
  }
  int start=0;
  byte[][] buff=new byte[cnt][];
  for (int pos=0; pos < cnt; ++pos) {
    byte id;
    if (pos == 0) {
      id=generateIFrame();
    }
 else {
      id=generateNextFrame();
    }
    if (start + dataSize > count) {
      dataSize=count - start;
    }
    buff[pos]=addFrame(id,cnt != 1 && pos < cnt - 1,tmp.toByteArray(),start,dataSize);
    start+=dataSize;
  }
  return buff;
}

Fixed version (ground truth):
public byte[][] splitToFrames(java.nio.ByteBuffer packet,int blockIndex,int[] index,int count,Command cmd,int resultChoice,boolean asList){
  ByteArrayOutputStream tmp=new ByteArrayOutputStream();
  if (this.getInterfaceType() == InterfaceType.GENERAL && !(Ciphering.getSecurity() != Security.NONE && frameSequence != -1)) {
    try {
      if (getServer()) {
        tmp.write(GXCommon.LLCReplyBytes);
      }
 else {
        tmp.write(GXCommon.LLCSendBytes);
      }
    }
 catch (    Exception ex) {
      throw new RuntimeException(ex.getMessage());
    }
  }
  if (cmd != Command.None && this.getUseLogicalNameReferencing()) {
    boolean moreBlocks=packet.limit() > getMaxReceivePDUSize() && packet.limit() > index[0] + count;
    tmp.write(cmd.getValue());
    if (asList) {
      tmp.write((byte)3);
    }
 else {
      tmp.write((byte)(moreBlocks ? 2 : 1));
    }
    tmp.write(getInvokeIDPriority());
    if (getServer()) {
      tmp.write(resultChoice);
    }
    if (moreBlocks) {
      tmp.write((byte)blockIndex >> 8);
      tmp.write((byte)blockIndex & 0xFF);
      tmp.write((byte)0);
      GXCommon.setObjectCount(count,tmp);
    }
  }
 else   if (cmd != Command.None && !this.getUseLogicalNameReferencing()) {
    tmp.write((byte)cmd.getValue());
  }
  if (Ciphering.getSecurity() != Security.NONE && frameSequence != -1) {
    try {
      int cnt=count;
      if (count + index[0] > packet.limit()) {
        cnt=packet.limit() - index[0];
      }
      tmp.write(packet.array(),index[0],cnt);
    }
 catch (    Exception ex) {
      throw new RuntimeException(ex.getMessage());
    }
    packet.clear();
    Ciphering.setFrameCounter(Ciphering.getFrameCounter() + 1);
    Command gloCmd;
    if (cmd == Command.ReadRequest || cmd == Command.GetRequest) {
      gloCmd=Command.GloGetRequest;
    }
 else     if (cmd == Command.WriteRequest || cmd == Command.SetRequest) {
      gloCmd=Command.GloSetRequest;
    }
 else     if (cmd == Command.MethodRequest) {
      gloCmd=Command.GloMethodRequest;
    }
 else     if (cmd == Command.ReadResponse || cmd == Command.GetResponse) {
      gloCmd=Command.GloGetResponse;
    }
 else     if (cmd == Command.WriteResponse || cmd == Command.SetResponse) {
      gloCmd=Command.GloSetResponse;
    }
 else     if (cmd == Command.MethodResponse) {
      gloCmd=Command.GloMethodResponse;
    }
 else {
      throw new GXDLMSException("String_Node_Str");
    }
    byte[] tmp2=tmp.toByteArray();
    packet=java.nio.ByteBuffer.wrap(GXDLMSChippering.EncryptAesGcm(gloCmd,Ciphering.getSecurity(),Ciphering.getFrameCounter(),Ciphering.getSystemTitle(),Ciphering.getBlockCipherKey(),Ciphering.getAuthenticationKey(),tmp2));
    packet.position(packet.limit());
    count=packet.position();
    tmp.reset();
    try {
      if (this.getInterfaceType() == InterfaceType.GENERAL) {
        if (getServer()) {
          tmp.write(GXCommon.LLCReplyBytes);
        }
 else {
          tmp.write(GXCommon.LLCSendBytes);
        }
      }
    }
 catch (    Exception ex) {
      throw new RuntimeException(ex.getMessage());
    }
  }
  int dataSize;
  if (this.getInterfaceType() == InterfaceType.NET) {
    dataSize=getMaxReceivePDUSize();
  }
 else {
    if (cmd == Command.GetRequest || cmd == Command.MethodRequest || cmd == Command.ReadRequest || cmd == Command.SetRequest || cmd == Command.WriteRequest) {
      dataSize=GXCommon.intValue(getLimits().getMaxInfoTX());
    }
 else {
      dataSize=GXCommon.intValue(getLimits().getMaxInfoRX());
    }
  }
  if (count + index[0] > packet.limit()) {
    count=packet.limit() - index[0];
  }
  packet.position(index[0]);
  byte[] tmp2=new byte[count];
  packet.get(tmp2);
  try {
    tmp.write(tmp2);
  }
 catch (  Exception ex) {
    throw new RuntimeException(ex.getMessage());
  }
  index[0]+=count;
  count=tmp.size();
  if (count < dataSize) {
    dataSize=count;
  }
  int cnt=(int)(count / dataSize);
  if (count % dataSize != 0) {
    ++cnt;
  }
  int start=0;
  byte[][] buff=new byte[cnt][];
  for (int pos=0; pos < cnt; ++pos) {
    byte id;
    if (pos == 0) {
      id=generateIFrame();
    }
 else {
      id=generateNextFrame();
    }
    if (start + dataSize > count) {
      dataSize=count - start;
    }
    buff[pos]=addFrame(id,cnt != 1 && pos < cnt - 1,tmp.toByteArray(),start,dataSize);
    start+=dataSize;
  }
  return buff;
}