nus-yam/ex-repair huggingface dataset:
Program: 107558
Project: 107558
Buggy source:
/** 
 * Tries to find an RTP header extensions with an ID of   {@link #extensionID}in <tt>pkt</tt> and tries to replace its timestamp with one generated locally (based on   {@link System#nanoTime()}).
 * @param pkt the packet to work on.
 * @return true if and only if an RTP extension with an ID of {@link #extensionID} was found in the packet, and its value was replaced.
 */
private boolean replaceExtension(RawPacket pkt){
  if (!pkt.getExtensionBit())   return false;
  byte[] buf=pkt.getBuffer();
  int extensionOffset=pkt.getOffset();
  extensionOffset+=RawPacket.FIXED_HEADER_SIZE;
  extensionOffset+=pkt.getCsrcCount() * 4;
  if (buf.length < extensionOffset + 4) {
    return false;
  }
  if (buf[extensionOffset++] != (byte)0xBE) {
    return false;
  }
  if (buf[extensionOffset++] != (byte)0xDE) {
    return false;
  }
  int lengthInWords=buf[extensionOffset++] << 8 | buf[extensionOffset++];
  int lengthInBytes=4 * (1 + lengthInWords);
  int innerOffset=0;
  while (extensionOffset < buf.length && innerOffset < lengthInBytes) {
    int id=(buf[extensionOffset] & 0xf0) >> 4;
    int len=buf[extensionOffset] & 0x0f;
    if (id == extensionID) {
      if (len == 2 && extensionOffset + 3 < buf.length) {
        setTimestamp(buf,extensionOffset + 1);
        return true;
      }
 else {
        logger.warn("String_Node_Str" + id + "String_Node_Str"+ "String_Node_Str"+ len);
        return true;
      }
    }
 else {
      innerOffset+=1 + len + 1;
      extensionOffset+=1 + len + 1;
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Tries to find an RTP header extensions with an ID of   {@link #extensionID}in <tt>pkt</tt> and tries to replace its timestamp with one generated locally (based on   {@link System#nanoTime()}).
 * @param pkt the packet to work on.
 * @return true if and only if an RTP extension with an ID of {@link #extensionID} was found in the packet, and its value was replaced.
 */
private boolean replaceExtension(RawPacket pkt){
  if (!pkt.getExtensionBit())   return false;
  byte[] buf=pkt.getBuffer();
  int extensionOffset=pkt.getOffset();
  extensionOffset+=RawPacket.FIXED_HEADER_SIZE;
  extensionOffset+=pkt.getCsrcCount() * 4;
  if (buf.length < extensionOffset + 4) {
    return false;
  }
  if (buf[extensionOffset++] != (byte)0xBE) {
    return false;
  }
  if (buf[extensionOffset++] != (byte)0xDE) {
    return false;
  }
  int lengthInWords=(buf[extensionOffset++] & 0xFF) << 8 | (buf[extensionOffset++] & 0xFF);
  int lengthInBytes=4 * (1 + lengthInWords);
  int innerOffset=0;
  while (extensionOffset < buf.length && innerOffset < lengthInBytes) {
    int id=(buf[extensionOffset] & 0xf0) >> 4;
    int len=buf[extensionOffset] & 0x0f;
    if (id == extensionID) {
      if (len == 2 && extensionOffset + 3 < buf.length) {
        setTimestamp(buf,extensionOffset + 1);
        return true;
      }
 else {
        logger.warn("String_Node_Str" + id + "String_Node_Str"+ "String_Node_Str"+ len);
        return true;
      }
    }
 else {
      innerOffset+=1 + len + 1;
      extensionOffset+=1 + len + 1;
    }
  }
  return false;
}
Program: 107559
Project: 107559
Buggy source:
/** 
 * Transforms the RFC2198 packet <tt>pkt</tt> into an array of RTP packets.
 */
private RawPacket[] reverseTransformSingle(RawPacket pkt,RawPacket[] pkts){
  byte[] buf=pkt.getBuffer();
  int off=pkt.getOffset();
  int hdrLen=pkt.getHeaderLength();
  int idx=off + hdrLen;
  int pktCount=1;
  while ((buf[idx] & 0x80) != 0) {
    pktCount++;
    idx+=4;
  }
  idx=off + hdrLen;
  if (pkts.length < pktCount)   pkts=new RawPacket[pktCount];
  if (pktCount != 1 && logger.isInfoEnabled())   logger.info("String_Node_Str");
  int payloadOffset=idx + (pktCount - 1) * 4 + 1;
  for (int i=1; i < pktCount; i++) {
    int blockLen=(buf[idx + 2] & 0x03) << 8 | (buf[idx + 3]);
    byte[] newBuf=new byte[hdrLen + blockLen];
    System.arraycopy(buf,payloadOffset,newBuf,0,hdrLen + blockLen);
    if (pkts[i] == null)     pkts[i]=new RawPacket();
    pkts[i].setBuffer(newBuf);
    pkts[i].setOffset(0);
    pkts[i].setLength(hdrLen + blockLen);
    pkts[i].setPayloadType((byte)(buf[idx] & 0xf7));
    idx+=4;
    payloadOffset+=blockLen;
  }
  pkt.setPayloadType((byte)(buf[idx] & 0x7f));
  System.arraycopy(buf,off,buf,off + payloadOffset - hdrLen,hdrLen);
  pkt.setOffset(off + payloadOffset - hdrLen);
  pkt.setLength(pkt.getLength() - (payloadOffset - hdrLen));
  pkts[0]=pkt;
  return pkts;
}

Fixed version (ground truth):
/** 
 * Transforms the RFC2198 packet <tt>pkt</tt> into an array of RTP packets.
 */
private RawPacket[] reverseTransformSingle(RawPacket pkt,RawPacket[] pkts){
  byte[] buf=pkt.getBuffer();
  int off=pkt.getOffset();
  int hdrLen=pkt.getHeaderLength();
  int idx=off + hdrLen;
  int pktCount=1;
  while ((buf[idx] & 0x80) != 0) {
    pktCount++;
    idx+=4;
  }
  idx=off + hdrLen;
  if (pkts.length < pktCount)   pkts=new RawPacket[pktCount];
  if (pktCount != 1 && logger.isInfoEnabled())   logger.info("String_Node_Str");
  int payloadOffset=idx + (pktCount - 1) * 4 + 1;
  for (int i=1; i < pktCount; i++) {
    int blockLen=(buf[idx + 2] & 0x03) << 8 | (buf[idx + 3] & 0xFF);
    byte[] newBuf=new byte[hdrLen + blockLen];
    System.arraycopy(buf,payloadOffset,newBuf,0,hdrLen + blockLen);
    if (pkts[i] == null)     pkts[i]=new RawPacket();
    pkts[i].setBuffer(newBuf);
    pkts[i].setOffset(0);
    pkts[i].setLength(hdrLen + blockLen);
    pkts[i].setPayloadType((byte)(buf[idx] & 0xf7));
    idx+=4;
    payloadOffset+=blockLen;
  }
  pkt.setPayloadType((byte)(buf[idx] & 0x7f));
  System.arraycopy(buf,off,buf,off + payloadOffset - hdrLen,hdrLen);
  pkt.setOffset(off + payloadOffset - hdrLen);
  pkt.setLength(pkt.getLength() - (payloadOffset - hdrLen));
  pkts[0]=pkt;
  return pkts;
}
Program: 107560
Project: 107560
Buggy source:
/** 
 * Returns the length in bytes of the RTCP packet contained in <tt>buf</tt> at offset <tt>off</tt>. Assumes that <tt>buf</tt> is valid at least until index <tt>off</tt>+3.
 * @return the length in bytes of the RTCP packet contained in <tt>buf</tt>at offset <tt>off</tt>.
 */
private static int getLengthInBytes(byte[] buf,int off,int len){
  if (len < 4)   return -1;
  int v=(buf[off] & 0xc0) >>> 6;
  if (RTCPHeader.VERSION != v)   return -1;
  int lengthInWords=(buf[off + 2] << 8) + buf[off + 3];
  int lengthInBytes=(lengthInWords + 1) * 4;
  if (len < lengthInBytes)   return -1;
  return lengthInBytes;
}

Fixed version (ground truth):
/** 
 * Returns the length in bytes of the RTCP packet contained in <tt>buf</tt> at offset <tt>off</tt>. Assumes that <tt>buf</tt> is valid at least until index <tt>off</tt>+3.
 * @return the length in bytes of the RTCP packet contained in <tt>buf</tt>at offset <tt>off</tt>.
 */
private static int getLengthInBytes(byte[] buf,int off,int len){
  if (len < 4)   return -1;
  int v=(buf[off] & 0xc0) >>> 6;
  if (RTCPHeader.VERSION != v)   return -1;
  int lengthInWords=((buf[off + 2] & 0xFF) << 8) | (buf[off + 3] & 0xFF);
  int lengthInBytes=(lengthInWords + 1) * 4;
  if (len < lengthInBytes)   return -1;
  return lengthInBytes;
}
Program: 107561
Project: 107561
Buggy source:
public static SctpNotification parse(byte[] data){
  int type=data[0] | (data[1] << 8);
switch (type) {
case SCTP_ASSOC_CHANGE:
    return new AssociationChange(data);
case SCTP_PEER_ADDR_CHANGE:
  return new PeerAddressChange(data);
case SCTP_SEND_FAILED:
return new SendFailed(data);
case SCTP_SENDER_DRY_EVENT:
return new SenderDry(data);
case SCTP_STREAM_RESET_EVENT:
return new StreamReset(data);
default :
return new SctpNotification(data);
}
}

Fixed version (ground truth):
public static SctpNotification parse(byte[] data){
  int type=(data[1] & 0xFF) << 8 | (data[0] & 0xFF);
switch (type) {
case SCTP_ASSOC_CHANGE:
    return new AssociationChange(data);
case SCTP_PEER_ADDR_CHANGE:
  return new PeerAddressChange(data);
case SCTP_SEND_FAILED:
return new SendFailed(data);
case SCTP_SENDER_DRY_EVENT:
return new SenderDry(data);
case SCTP_STREAM_RESET_EVENT:
return new StreamReset(data);
default :
return new SctpNotification(data);
}
}
Program: 107562
Project: 107562
Buggy source:
/** 
 * Computes the RTT with the data (LSR and DLSR) contained in the last RTCP Sender Report (RTCP feedback). This RTT computation is based on RFC3550, section 6.4.1, subsection "delay since last SR (DLSR): 32 bits".
 * @param feedback The last RTCP feedback received by the MediaStream.
 * @return The RTT in milliseconds, or -1 if the RTT is not computable.
 */
private long computeRTTInMs(RTCPFeedback feedback){
  long now=System.currentTimeMillis();
  long lsr=feedback.getLSR();
  long dlsr=feedback.getDLSR();
  int rtt=RecvSSRCInfo.getRoundTripDelay(now,lsr,dlsr);
  if ((rtt >= 65536) && logger.isInfoEnabled()) {
    logger.info("String_Node_Str" + mediaStreamImpl.getName() + "String_Node_Str"+ rtt+ "String_Node_Str"+ now+ "String_Node_Str"+ lsr+ "String_Node_Str"+ dlsr);
  }
  return rtt;
}

Fixed version (ground truth):
/** 
 * Computes the RTT with the data (LSR and DLSR) contained in the last RTCP Sender Report (RTCP feedback). This RTT computation is based on RFC3550, section 6.4.1, subsection "delay since last SR (DLSR): 32 bits".
 * @param feedback The last RTCP feedback received by the MediaStream.
 * @return The RTT in milliseconds, or -1 if the RTT is not computable.
 */
private int computeRTTInMs(RTCPFeedback feedback){
  long now=System.currentTimeMillis();
  long lsr=feedback.getLSR();
  long dlsr=feedback.getDLSR();
  int rtt=-1;
  if (lsr > 0 && dlsr > 0) {
    now=maybeEstimateRemoteClock(feedback.getSSRC(),now);
    rtt=getRoundTripDelay(now,lsr,dlsr);
  }
  if (rtt < 0 || rtt >= 3000) {
    logger.info("String_Node_Str" + mediaStreamImpl.getName() + "String_Node_Str"+ rtt+ "String_Node_Str"+ now+ "String_Node_Str"+ lsr+ "String_Node_Str"+ dlsr);
    rtt=-1;
  }
  return rtt;
}
Program: 107563
Project: 107563
Buggy source:
/** 
 * Updates this stream stats with the new feedback received.
 * @param feedback The last RTCP feedback received by the MediaStream.
 */
private void updateNewReceivedFeedback(RTCPFeedback feedback){
  StreamDirection streamDirection=StreamDirection.UPLOAD;
  updateJitterRTPTimestampUnits(feedback,streamDirection);
  long uploadNewNbRecv=feedback.getXtndSeqNum();
  nbPacketsLostUpload=feedback.getNumLost();
  long newNbLost=nbPacketsLostUpload - nbLost[streamDirection.ordinal()];
  long nbSteps=uploadNewNbRecv - uploadFeedbackNbPackets;
  updateNbLoss(streamDirection,newNbLost,nbSteps);
  uploadFeedbackNbPackets=uploadNewNbRecv;
  setRttMs(computeRTTInMs(feedback));
}

Fixed version (ground truth):
/** 
 * Updates this stream stats with the new feedback received.
 * @param feedback The last RTCP feedback received by the MediaStream.
 */
private void updateNewReceivedFeedback(RTCPFeedback feedback){
  StreamDirection streamDirection=StreamDirection.UPLOAD;
  updateJitterRTPTimestampUnits(feedback,streamDirection);
  long uploadNewNbRecv=feedback.getXtndSeqNum();
  nbPacketsLostUpload=feedback.getNumLost();
  long newNbLost=nbPacketsLostUpload - nbLost[streamDirection.ordinal()];
  long nbSteps=uploadNewNbRecv - uploadFeedbackNbPackets;
  updateNbLoss(streamDirection,newNbLost,nbSteps);
  uploadFeedbackNbPackets=uploadNewNbRecv;
  int rtt=computeRTTInMs(feedback);
  if (rtt >= 0) {
    setRttMs(rtt);
  }
}
Program: 107564
Project: 107564
Buggy source:
/** 
 * Makes <tt>RTCPSRPacket</tt>s for all the RTP streams that we're sending.
 * @return a <tt>List</tt> of <tt>RTCPSRPacket</tt> for all the RTP streamsthat we're sending.
 */
private List<RTCPSRPacket> makeSRs(long time){
  List<RTCPSRPacket> srs=new ArrayList<>();
  for (  RTPStatsEntry rtpStatsEntry : rtpStatsMap.values()) {
    int ssrc=rtpStatsEntry.getSsrc();
    RemoteClock estimate=remoteClockEstimator.estimate(ssrc,time);
    if (estimate == null) {
      continue;
    }
    RTCPSRPacket sr=new RTCPSRPacket(ssrc,MIN_RTCP_REPORT_BLOCKS_ARRAY);
    long estimatedRemoteTime=estimate.getRemoteTime();
    long secs=estimatedRemoteTime / 1000L;
    double fraction=(estimatedRemoteTime - secs * 1000L) / 1000D;
    sr.ntptimestamplsw=(int)(fraction * 4294967296D);
    sr.ntptimestampmsw=secs;
    sr.rtptimestamp=estimate.getRtpTimestamp();
    sr.packetcount=rtpStatsEntry.getPacketsSent();
    sr.octetcount=rtpStatsEntry.getBytesSent();
    srs.add(sr);
  }
  return srs;
}

Fixed version (ground truth):
/** 
 * Makes <tt>RTCPSRPacket</tt>s for all the RTP streams that we're sending.
 * @return a <tt>List</tt> of <tt>RTCPSRPacket</tt> for all the RTP streamsthat we're sending.
 */
private List<RTCPSRPacket> makeSRs(long time){
  List<RTCPSRPacket> srs=new ArrayList<>();
  for (  RTPStatsEntry rtpStatsEntry : rtpStatsMap.values()) {
    int ssrc=rtpStatsEntry.getSsrc();
    RemoteClock estimate=remoteClockEstimator.estimate(ssrc,time);
    if (estimate == null) {
      continue;
    }
    RTCPSRPacket sr=new RTCPSRPacket(ssrc,MIN_RTCP_REPORT_BLOCKS_ARRAY);
    long estimatedRemoteTime=estimate.getRemoteTime();
    long ntpTime=TimeUtils.toNtpTime(estimatedRemoteTime);
    sr.ntptimestampmsw=TimeUtils.getMsw(ntpTime);
    sr.ntptimestamplsw=TimeUtils.getLsw(ntpTime);
    sr.rtptimestamp=estimate.getRtpTimestamp();
    sr.packetcount=rtpStatsEntry.getPacketsSent();
    sr.octetcount=rtpStatsEntry.getBytesSent();
    srs.add(sr);
  }
  return srs;
}
Program: 107565
Project: 107565
Buggy source:
/** 
 * Ctor.
 * @param ssrc
 * @param remoteTime
 * @param rtpTimestamp
 * @param frequencyHz
 */
ReceivedRemoteClock(int ssrc,long remoteTime,int rtpTimestamp,int frequencyHz){
  this.ssrc=ssrc;
  this.remoteClock=new RemoteClock(remoteTime,rtpTimestamp);
  this.frequencyHz=frequencyHz;
  this.receivedTime=System.currentTimeMillis();
}

Fixed version (ground truth):
/** 
 * Ctor.
 * @param ssrc
 * @param remoteTime the remote time in milliseconds since the epoch
 * @param rtpTimestamp the RTP timestamp corresponding to<tt>remoteTime</tt>.
 * @param frequencyHz the RTP clock rate.
 */
ReceivedRemoteClock(int ssrc,long remoteTime,int rtpTimestamp,int frequencyHz){
  this.ssrc=ssrc;
  this.remoteClock=new RemoteClock(remoteTime,rtpTimestamp);
  this.frequencyHz=frequencyHz;
  this.receivedTime=System.currentTimeMillis();
}
Program: 107566
Project: 107566
Buggy source:
/** 
 * Inspect an <tt>RTCPCompoundPacket</tt> and build-up the state for future estimations.
 * @param pkt
 */
public void update(RTCPCompoundPacket pkt){
  if (pkt == null || pkt.packets == null || pkt.packets.length == 0) {
    return;
  }
  for (  RTCPPacket rtcpPacket : pkt.packets) {
switch (rtcpPacket.type) {
case RTCPPacket.SR:
      RTCPSRPacket srPacket=(RTCPSRPacket)rtcpPacket;
    int ssrc=srPacket.ssrc;
  long fraction=Math.round(1000D * srPacket.ntptimestamplsw / 0x100000000L);
long msb=srPacket.ntptimestampmsw & 0x80000000L;
long remoteTime=(msb == 0) ? MSB0_BASE_TIME + (srPacket.ntptimestampmsw * 1000) + fraction : MSB1_BASE_TIME + (srPacket.ntptimestampmsw * 1000) + fraction;
int frequencyHz=-1;
if (receivedClocks.containsKey(ssrc)) {
ReceivedRemoteClock oldStats=receivedClocks.get(ssrc);
RemoteClock oldRemoteClock=oldStats.getRemoteClock();
frequencyHz=Math.round((float)(((int)srPacket.rtptimestamp - oldRemoteClock.getRtpTimestamp()) & 0xffffffffl) / (remoteTime - oldRemoteClock.getRemoteTime()));
}
receivedClocks.put(ssrc,new ReceivedRemoteClock(ssrc,remoteTime,(int)srPacket.rtptimestamp,frequencyHz));
break;
case RTCPPacket.SDES:
break;
}
}
}

Fixed version (ground truth):
/** 
 * Inspect an <tt>RTCPCompoundPacket</tt> and build-up the state for future estimations.
 * @param pkt
 */
public void update(RTCPCompoundPacket pkt){
  if (pkt == null || pkt.packets == null || pkt.packets.length == 0) {
    return;
  }
  for (  RTCPPacket rtcpPacket : pkt.packets) {
switch (rtcpPacket.type) {
case RTCPPacket.SR:
      RTCPSRPacket sr=(RTCPSRPacket)rtcpPacket;
    int ssrc=sr.ssrc;
  long ntpTime=TimeUtils.constuctNtp(sr.ntptimestampmsw,sr.ntptimestamplsw);
long remoteTime=TimeUtils.getTime(ntpTime);
int frequencyHz=-1;
if (receivedClocks.containsKey(ssrc)) {
ReceivedRemoteClock oldStats=receivedClocks.get(ssrc);
RemoteClock oldRemoteClock=oldStats.getRemoteClock();
frequencyHz=Math.round((float)(((int)sr.rtptimestamp - oldRemoteClock.getRtpTimestamp()) & 0xffffffffl) / (remoteTime - oldRemoteClock.getRemoteTime()));
}
receivedClocks.put(ssrc,new ReceivedRemoteClock(ssrc,remoteTime,(int)sr.rtptimestamp,frequencyHz));
break;
case RTCPPacket.SDES:
break;
}
}
}
Program: 107567
Project: 107567
Buggy source:
/** 
 * Ctor.
 * @param ssrcRewritingEngine the owner of this instance.
 * @param ssrcTarget the target SSRC for this <tt>SsrcGroupRewriter</tt>.
 */
public SsrcGroupRewriter(SsrcRewritingEngine ssrcRewritingEngine,Integer ssrcTarget){
  this.ssrcRewritingEngine=ssrcRewritingEngine;
  this.ssrcTarget=ssrcTarget;
  this.currentExtendedSeqnumBase=RANDOM.nextInt(0x10000);
}

Fixed version (ground truth):
/** 
 * Ctor.
 * @param ssrcRewritingEngine the owner of this instance.
 * @param ssrcTarget the target SSRC for this <tt>SsrcGroupRewriter</tt>.
 */
public SsrcGroupRewriter(SsrcRewritingEngine ssrcRewritingEngine,Integer ssrcTarget,int seqnumBase){
  this.ssrcRewritingEngine=ssrcRewritingEngine;
  this.ssrcTarget=ssrcTarget;
  this.currentExtendedSeqnumBase=seqnumBase;
}
Program: 107568
Project: 107568
Buggy source:
@Override public RawPacket transform(RawPacket pkt){
  if (pkt == null) {
    return pkt;
  }
  if (!initialized) {
    return pkt;
  }
  int ssrc=pkt.getSSRC();
  SsrcGroupRewriter ssrcGroupRewriter=origin2rewriter.get(ssrc);
  if (ssrcGroupRewriter == null) {
    return pkt;
  }
 else {
    return ssrcGroupRewriter.rewriteRTP(pkt);
  }
}

Fixed version (ground truth):
@Override public RawPacket transform(RawPacket pkt){
  if (pkt == null) {
    return pkt;
  }
  seqnumBaseKeeper.update(pkt);
  if (!initialized) {
    return pkt;
  }
  int ssrc=pkt.getSSRC();
  SsrcGroupRewriter ssrcGroupRewriter=origin2rewriter.get(ssrc);
  if (ssrcGroupRewriter == null) {
    return pkt;
  }
 else {
    return ssrcGroupRewriter.rewriteRTP(pkt);
  }
}
Program: 107569
Project: 107569
Buggy source:
/** 
 * Sets up the engine so that ssrcOrig is rewritten to ssrcTarget.
 * @param ssrcOrig
 * @param ssrcTarget
 */
private synchronized void map(Integer ssrcOrig,Integer ssrcTarget){
  if (ssrcOrig == null) {
    return;
  }
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + (ssrcOrig & 0xffffffffl) + "String_Node_Str"+ (ssrcTarget & 0xffffffffl));
  }
  if (ssrcTarget != null && ssrcTarget != UNMAP_SSRC) {
    RefCount<SsrcGroupRewriter> refCount=target2rewriter.get(ssrcTarget);
    if (refCount == null) {
      refCount=new RefCount<>(new SsrcGroupRewriter(this,ssrcTarget));
      target2rewriter.put(ssrcTarget,refCount);
    }
    SsrcGroupRewriter oldSsrcGroupRewriter=origin2rewriter.put(ssrcOrig,refCount.getReferent());
    if (oldSsrcGroupRewriter == null) {
      refCount.increase();
    }
 else {
    }
  }
 else {
    SsrcGroupRewriter ssrcGroupRewriter=origin2rewriter.remove(ssrcOrig);
    if (ssrcGroupRewriter != null) {
      RefCount<SsrcGroupRewriter> refCount=target2rewriter.get(ssrcGroupRewriter.getSSRCTarget());
      refCount.decrease();
    }
  }
}

Fixed version (ground truth):
/** 
 * Sets up the engine so that ssrcOrig is rewritten to ssrcTarget.
 * @param ssrcOrig
 * @param ssrcTarget
 */
private synchronized void map(Integer ssrcOrig,Integer ssrcTarget){
  if (ssrcOrig == null) {
    return;
  }
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str" + (ssrcOrig & 0xffffffffl) + "String_Node_Str"+ (ssrcTarget & 0xffffffffl));
  }
  if (ssrcTarget != null && ssrcTarget != UNMAP_SSRC) {
    RefCount<SsrcGroupRewriter> refCount=target2rewriter.get(ssrcTarget);
    if (refCount == null) {
      refCount=new RefCount<>(seqnumBaseKeeper.createSsrcGroupRewriter(this,ssrcTarget));
      target2rewriter.put(ssrcTarget,refCount);
    }
    SsrcGroupRewriter oldSsrcGroupRewriter=origin2rewriter.put(ssrcOrig,refCount.getReferent());
    if (oldSsrcGroupRewriter == null) {
      refCount.increase();
    }
 else {
    }
  }
 else {
    SsrcGroupRewriter ssrcGroupRewriter=origin2rewriter.remove(ssrcOrig);
    if (ssrcGroupRewriter != null) {
      RefCount<SsrcGroupRewriter> refCount=target2rewriter.get(ssrcGroupRewriter.getSSRCTarget());
      refCount.decrease();
    }
  }
}
Program: 107570
Project: 107570
Buggy source:
/** 
 * @param ssOrigSeqnum
 * @return
 */
int extendOriginalSequenceNumber(short ssOrigSeqnum){
  ExtendedSequenceNumberInterval mostRecentInterval=currentExtendedSequenceNumberInterval;
  if (mostRecentInterval == null) {
    Map.Entry<Integer,ExtendedSequenceNumberInterval> entry=intervals.lastEntry();
    if (entry != null) {
      mostRecentInterval=entry.getValue();
    }
  }
  if (mostRecentInterval == null) {
    return ssOrigSeqnum & 0x0000ffff;
  }
  int usOriginalSequenceNumber=ssOrigSeqnum & 0x0000ffff;
  int usHighestSeenSeqnum=mostRecentInterval.extendedMaxOrig & 0x0000ffff;
  if (usOriginalSequenceNumber - usHighestSeenSeqnum > 0) {
    if (System.currentTimeMillis() - mostRecentInterval.lastSeen - RETRANSMISSIONS_FRONTIER_MS < 0) {
      if (usOriginalSequenceNumber - (usHighestSeenSeqnum + MAX_UNSIGNED_SHORT) - MEDIAN_UNSIGNED_SHORT > 0) {
        return ((((usHighestSeenSeqnum & 0xffff0000) >> 4) - 1) << 4) | (usOriginalSequenceNumber & 0x0000ffff);
      }
 else {
        return (usHighestSeenSeqnum & 0xffff0000) | (usOriginalSequenceNumber & 0x0000ffff);
      }
    }
 else {
      return ((((usHighestSeenSeqnum & 0xffff0000) >> 4) + 1) << 4) | (usOriginalSequenceNumber & 0x0000ffff);
    }
  }
 else {
    if (System.currentTimeMillis() - mostRecentInterval.lastSeen - RETRANSMISSIONS_FRONTIER_MS < 0) {
      if ((usHighestSeenSeqnum - usOriginalSequenceNumber) - MEDIAN_UNSIGNED_SHORT > 0) {
        return ((((usHighestSeenSeqnum & 0xffff0000) >> 4) + 1) << 4) | (usOriginalSequenceNumber & 0x0000ffff);
      }
 else {
        return (usHighestSeenSeqnum & 0xffff0000) | (usOriginalSequenceNumber & 0x0000ffff);
      }
    }
 else {
      return ((((usHighestSeenSeqnum & 0xffff0000) >> 4) + 1) << 4) | (usOriginalSequenceNumber & 0x0000ffff);
    }
  }
}

Fixed version (ground truth):
/** 
 * @param ssOrigSeqnum
 * @return
 */
int extendOriginalSequenceNumber(short ssOrigSeqnum){
  ExtendedSequenceNumberInterval mostRecentInterval=currentExtendedSequenceNumberInterval;
  if (mostRecentInterval == null) {
    Map.Entry<Integer,ExtendedSequenceNumberInterval> entry=intervals.lastEntry();
    if (entry != null) {
      mostRecentInterval=entry.getValue();
    }
  }
  int usOrigSeqnum=ssOrigSeqnum & 0x0000ffff;
  if (mostRecentInterval == null) {
    return usOrigSeqnum;
  }
  int extendedMaxOrig=mostRecentInterval.extendedMaxOrig;
  int usMaxSeqnum=extendedMaxOrig & 0x0000ffff;
  int cycles=extendedMaxOrig & 0xffff0000;
  int delta=usOrigSeqnum - usMaxSeqnum;
  boolean inRetransmissionFrontier=System.currentTimeMillis() - mostRecentInterval.lastSeen < RETRANSMISSION_FRONTIER_MS;
  if (delta > 0) {
    if (inRetransmissionFrontier) {
      if (delta > MEDIAN_UNSIGNED_SHORT) {
        cycles-=0x10000;
      }
 else {
      }
    }
 else {
      cycles+=0x10000;
    }
  }
 else {
    if (inRetransmissionFrontier) {
      if (-delta > MEDIAN_UNSIGNED_SHORT) {
        cycles+=0x10000;
      }
 else {
      }
    }
 else {
      cycles+=0x10000;
    }
  }
  return usOrigSeqnum + cycles;
}
Program: 107571
Project: 107571
Buggy source:
/** 
 */
public RawPacket rewriteRTP(RawPacket pkt){
  short seqnum=(short)pkt.getSequenceNumber();
  int origExtendedSequenceNumber=extendOriginalSequenceNumber(seqnum);
  ExtendedSequenceNumberInterval retransmissionInterval=findRetransmissionInterval(origExtendedSequenceNumber);
  if (retransmissionInterval != null) {
    logDebug("String_Node_Str" + (seqnum & 0xffff) + "String_Node_Str"+ (pkt.getSSRC() & 0xffffffffl)+ "String_Node_Str");
    return retransmissionInterval.rewriteRTP(pkt);
  }
  if (currentExtendedSequenceNumberInterval == null) {
    currentExtendedSequenceNumberInterval=new ExtendedSequenceNumberInterval(this,origExtendedSequenceNumber,ssrcGroupRewriter.currentExtendedSeqnumBase);
    currentExtendedSequenceNumberInterval.lastSeen=System.currentTimeMillis();
  }
 else {
    currentExtendedSequenceNumberInterval.extendedMaxOrig=origExtendedSequenceNumber;
    currentExtendedSequenceNumberInterval.maxTimestamp=pkt.getTimestamp();
    currentExtendedSequenceNumberInterval.lastSeen=System.currentTimeMillis();
  }
  if (SsrcRewritingEngine.logger.isDebugEnabled()) {
    long maxTimestamp=ssrcGroupRewriter.maxTimestamp;
    if (pkt.getTimestamp() < maxTimestamp) {
      logDebug("String_Node_Str");
      pkt.setTimestamp(maxTimestamp + 1);
    }
  }
  return currentExtendedSequenceNumberInterval.rewriteRTP(pkt);
}

Fixed version (ground truth):
/** 
 * @param pkt
 */
public RawPacket rewriteRTP(RawPacket pkt){
  short seqnum=(short)pkt.getSequenceNumber();
  int origExtendedSequenceNumber=extendOriginalSequenceNumber(seqnum);
  ExtendedSequenceNumberInterval retransmissionInterval=findRetransmissionInterval(origExtendedSequenceNumber);
  boolean debug=SsrcRewritingEngine.logger.isDebugEnabled();
  if (retransmissionInterval != null) {
    if (debug) {
      logDebug("String_Node_Str" + (seqnum & 0xffff) + "String_Node_Str"+ (pkt.getSSRC() & 0xffffffffl)+ "String_Node_Str");
    }
    return retransmissionInterval.rewriteRTP(pkt);
  }
  long timestamp=pkt.getTimestamp();
  if (currentExtendedSequenceNumberInterval == null) {
    currentExtendedSequenceNumberInterval=new ExtendedSequenceNumberInterval(this,origExtendedSequenceNumber,ssrcGroupRewriter.currentExtendedSeqnumBase);
  }
 else {
    currentExtendedSequenceNumberInterval.extendedMaxOrig=origExtendedSequenceNumber;
    currentExtendedSequenceNumberInterval.maxTimestamp=timestamp;
  }
  currentExtendedSequenceNumberInterval.lastSeen=System.currentTimeMillis();
  long maxTimestamp=ssrcGroupRewriter.maxTimestamp;
  if (timestamp < maxTimestamp) {
    if (debug) {
      logDebug("String_Node_Str");
    }
    pkt.setTimestamp(maxTimestamp + 1);
  }
  return currentExtendedSequenceNumberInterval.rewriteRTP(pkt);
}
Program: 107573
Project: 107573
Buggy source:
/** 
 * Transforms the RFC2198 packet <tt>pkt</tt> into an array of RTP packets.
 */
private RawPacket[] reverseTransformSingle(RawPacket pkt,RawPacket[] pkts){
  byte[] buf=pkt.getBuffer();
  int off=pkt.getOffset();
  int hdrLen=pkt.getHeaderLength();
  int idx=off + hdrLen;
  int pktCount=1;
  while ((buf[idx] & 0x80) != 0) {
    pktCount++;
    idx+=4;
  }
  idx=off + hdrLen;
  if (pkts.length < pktCount)   pkts=new RawPacket[pktCount];
  if (pktCount != 1 && logger.isInfoEnabled())   logger.info("String_Node_Str");
  int payloadOffset=idx + (pktCount - 1) * 4 + 1;
  for (int i=1; i < pktCount; i++) {
    int blockLen=(buf[idx + 2] & 0x03) << 8 | (buf[idx + 3]);
    byte[] newBuf=new byte[hdrLen + blockLen];
    System.arraycopy(buf,payloadOffset,newBuf,0,hdrLen + blockLen);
    if (pkts[i] == null)     pkts[i]=new RawPacket();
    pkts[i].setBuffer(newBuf);
    pkts[i].setOffset(0);
    pkts[i].setLength(hdrLen + blockLen);
    pkts[i].setPayloadType((byte)(buf[idx] & 0xf7));
    idx+=4;
    payloadOffset+=blockLen;
  }
  pkt.setPayloadType((byte)(buf[idx] & 0x7f));
  System.arraycopy(buf,payloadOffset,buf,hdrLen,pkt.getLength() - payloadOffset);
  pkt.setLength(pkt.getLength() - (payloadOffset - hdrLen));
  pkts[0]=pkt;
  return pkts;
}

Fixed version (ground truth):
/** 
 * Transforms the RFC2198 packet <tt>pkt</tt> into an array of RTP packets.
 */
private RawPacket[] reverseTransformSingle(RawPacket pkt,RawPacket[] pkts){
  byte[] buf=pkt.getBuffer();
  int off=pkt.getOffset();
  int hdrLen=pkt.getHeaderLength();
  int idx=off + hdrLen;
  int pktCount=1;
  while ((buf[idx] & 0x80) != 0) {
    pktCount++;
    idx+=4;
  }
  idx=off + hdrLen;
  if (pkts.length < pktCount)   pkts=new RawPacket[pktCount];
  if (pktCount != 1 && logger.isInfoEnabled())   logger.info("String_Node_Str");
  int payloadOffset=idx + (pktCount - 1) * 4 + 1;
  for (int i=1; i < pktCount; i++) {
    int blockLen=(buf[idx + 2] & 0x03) << 8 | (buf[idx + 3]);
    byte[] newBuf=new byte[hdrLen + blockLen];
    System.arraycopy(buf,payloadOffset,newBuf,0,hdrLen + blockLen);
    if (pkts[i] == null)     pkts[i]=new RawPacket();
    pkts[i].setBuffer(newBuf);
    pkts[i].setOffset(0);
    pkts[i].setLength(hdrLen + blockLen);
    pkts[i].setPayloadType((byte)(buf[idx] & 0xf7));
    idx+=4;
    payloadOffset+=blockLen;
  }
  pkt.setPayloadType((byte)(buf[idx] & 0x7f));
  System.arraycopy(buf,off,buf,off + payloadOffset - hdrLen,hdrLen);
  pkt.setOffset(off + payloadOffset - hdrLen);
  pkt.setLength(pkt.getLength() - (payloadOffset - hdrLen));
  pkts[0]=pkt;
  return pkts;
}
Program: 107574
Project: 107574
Buggy source:
/** 
 * Gets the set of sequence numbers reported lost in this NACK packet.
 * @return
 */
synchronized public Collection<Integer> getLostPackets(){
  if (lostPackets != null)   return lostPackets;
  lostPackets=new LinkedList<Integer>();
  for (int i=0; i < (fci.length / 4); i++) {
    int pid=fci[i * 4 + 0] << 8 | fci[i * 4 + 1];
    lostPackets.add(pid);
    for (int j=0; j < 8; j++)     if (0 != (fci[i * 4 + 2] & (1 << j)))     lostPackets.add((pid + 1 + 8+ j) % (1 << 16));
    for (int j=0; j < 8; j++)     if (0 != (fci[i * 4 + 3] & (1 << j)))     lostPackets.add((pid + 1 + j) % (1 << 16));
  }
  return lostPackets;
}

Fixed version (ground truth):
/** 
 * Gets the set of sequence numbers reported lost in this NACK packet.
 * @return
 */
synchronized public Collection<Integer> getLostPackets(){
  if (lostPackets != null)   return lostPackets;
  lostPackets=new LinkedList<Integer>();
  if (fci != null) {
    for (int i=0; i < (fci.length / 4); i++) {
      int pid=(0xFF & fci[i * 4 + 0]) << 8 | (0xFF & fci[i * 4 + 1]);
      lostPackets.add(pid);
      for (int j=0; j < 8; j++)       if (0 != (fci[i * 4 + 2] & (1 << j)))       lostPackets.add((pid + 1 + 8+ j) % (1 << 16));
      for (int j=0; j < 8; j++)       if (0 != (fci[i * 4 + 3] & (1 << j)))       lostPackets.add((pid + 1 + j) % (1 << 16));
    }
  }
  return lostPackets;
}
Program: 107576
Project: 107576
Buggy source:
public boolean addEngine(TransformEngine engine){
  if (engine == null)   throw new NullPointerException("String_Node_Str");
synchronized (this) {
    TransformEngine[] oldValue=this.engineChain;
    for (    TransformEngine e : oldValue) {
      if (engine.equals(e))       return false;
    }
    int oldLength=oldValue.length;
    TransformEngine[] newValue=new TransformEngine[oldLength + 1];
    if (oldLength != 0)     System.arraycopy(oldValue,0,newValue,0,oldLength);
    newValue[oldLength]=engine;
  }
  return true;
}

Fixed version (ground truth):
public boolean addEngine(TransformEngine engine){
  if (engine == null)   throw new NullPointerException("String_Node_Str");
synchronized (this) {
    TransformEngine[] oldValue=this.engineChain;
    for (    TransformEngine e : oldValue) {
      if (engine.equals(e))       return false;
    }
    int oldLength=oldValue.length;
    TransformEngine[] newValue=new TransformEngine[oldLength + 1];
    if (oldLength != 0)     System.arraycopy(oldValue,0,newValue,0,oldLength);
    newValue[oldLength]=engine;
    this.engineChain=newValue;
  }
  return true;
}
Program: 107577
Project: 107577
Buggy source:
/** 
 * Transforms the RFC2198 packet <tt>pkt</tt> into an array of RTP packets.
 */
private RawPacket[] reverseTransformSingle(RawPacket pkt,RawPacket[] pkts){
  byte[] buf=pkt.getBuffer();
  int off=pkt.getOffset();
  int hdrLen=pkt.getHeaderLength();
  int idx=off + hdrLen;
  int pktCount=1;
  while ((buf[idx] & 0x80) != 0) {
    pktCount++;
    idx+=4;
  }
  idx=off + hdrLen;
  if (pkts.length < pktCount)   pkts=new RawPacket[pktCount];
  if (pktCount != 1 && logger.isInfoEnabled())   logger.info("String_Node_Str");
  int payloadOffset=idx + (pktCount - 1) * 4 + 1;
  for (int i=1; i < pktCount; i++) {
    int blockLen=(buf[idx + 2] & 0x03) << 8 | (buf[idx + 3]);
    byte[] newBuf=new byte[hdrLen + blockLen];
    System.arraycopy(buf,payloadOffset,newBuf,0,hdrLen + blockLen);
    if (pkts[i] == null)     pkts[i]=new RawPacket();
    pkts[i].setBuffer(newBuf);
    pkts[i].setOffset(0);
    pkts[i].setLength(hdrLen + blockLen);
    pkts[i].setPayloadType((byte)(buf[idx] & 0xf7));
    idx+=4;
    payloadOffset+=blockLen;
  }
  pkt.setPayloadType((byte)(buf[idx] & 0x7f));
  System.arraycopy(buf,off,buf,off + payloadOffset - hdrLen,hdrLen);
  pkt.setOffset(off + payloadOffset - hdrLen);
  pkt.setLength(pkt.getLength() - (payloadOffset - hdrLen));
  pkts[0]=pkt;
  return pkts;
}

Fixed version (ground truth):
/** 
 * Transforms the RFC2198 packet <tt>pkt</tt> into an array of RTP packets.
 */
private RawPacket[] reverseTransformSingle(RawPacket pkt,RawPacket[] pkts){
  byte[] buf=pkt.getBuffer();
  int off=pkt.getOffset();
  int hdrLen=pkt.getHeaderLength();
  int idx=off + hdrLen;
  int pktCount=1;
  while ((buf[idx] & 0x80) != 0) {
    pktCount++;
    idx+=4;
  }
  idx=off + hdrLen;
  if (pkts.length < pktCount)   pkts=new RawPacket[pktCount];
  if (pktCount != 1 && logger.isInfoEnabled())   logger.info("String_Node_Str");
  int payloadOffset=idx + (pktCount - 1) * 4 + 1;
  for (int i=1; i < pktCount; i++) {
    int blockLen=(buf[idx + 2] & 0x03) << 8 | (buf[idx + 3]);
    byte[] newBuf=new byte[hdrLen + blockLen];
    System.arraycopy(buf,payloadOffset,newBuf,0,hdrLen + blockLen);
    if (pkts[i] == null)     pkts[i]=new RawPacket();
    pkts[i].setBuffer(newBuf);
    pkts[i].setOffset(0);
    pkts[i].setLength(hdrLen + blockLen);
    pkts[i].setPayloadType((byte)(buf[idx] & 0xf7));
    idx+=4;
    payloadOffset+=blockLen;
  }
  pkt.setPayloadType((byte)(buf[idx] & 0x7f));
  System.arraycopy(buf,payloadOffset,buf,hdrLen,pkt.getLength() - payloadOffset);
  pkt.setLength(pkt.getLength() - (payloadOffset - hdrLen));
  pkts[0]=pkt;
  return pkts;
}
Program: 107579
Project: 107579
Buggy source:
/** 
 * First-order allpass filter.
 * @param in Q25 input signal [len]
 * @param in_offset offset of valid data.
 * @param S Q25 state [1]
 * @param S_offset offset of valid data.
 * @param A Q15 coefficient    (0 <= A < 32768)
 * @param out Q25 output signal [len]
 * @param out_offset offset of valid data.
 * @param len Number of samples
 */
static void SKP_Silk_allpass_int(final int[] in,int in_offset,int[] S,int S_offset,int A,int[] out,int out_offset,final int len){
  int Y2, X2, S0;
  int k;
  S0=S[S_offset + 0];
  for (k=len - 1; k >= 0; k--) {
    Y2=in[in_offset + 0] - S0;
    X2=(Y2 >> 15) * A + (((Y2 & 0x00007FFF) * A) >> 15);
    (out[out_offset++])=S0 + X2;
    S0=in[in_offset++] + X2;
  }
  S[S_offset + 0]=S0;
}

Fixed version (ground truth):
/** 
 * First-order allpass filter.
 * @param in Q25 input signal [len]
 * @param in_offset offset of valid data.
 * @param S Q25 state [1]
 * @param S_offset offset of valid data.
 * @param A Q15 coefficient    (0 <= A < 32768)
 * @param out Q25 output signal [len]
 * @param out_offset offset of valid data.
 * @param len Number of samples
 */
static void SKP_Silk_allpass_int(final int[] in,int in_offset,int[] S,int S_offset,int A,int[] out,int out_offset,final int len){
  int Y2, X2, S0;
  int k;
  S0=S[S_offset];
  for (k=len - 1; k >= 0; k--) {
    Y2=in[in_offset] - S0;
    X2=(Y2 >> 15) * A + (((Y2 & 0x00007FFF) * A) >> 15);
    out[out_offset++]=S0 + X2;
    S0=in[in_offset++] + X2;
  }
  S[S_offset]=S0;
}
Program: 107580
Project: 107580
Buggy source:
/** 
 * Helper function for A2NLSF(..). Polynomial evaluation.
 * @param p Polynomial, QPoly
 * @param x Evaluation point, Q12
 * @param dd  Order
 * @return return the polynomial evaluation, in QPoly
 */
static int SKP_Silk_A2NLSF_eval_poly(int[] p,final int x,final int dd){
  int n;
  int x_Q16, y32;
  y32=p[dd];
  x_Q16=x << 4;
  for (n=dd - 1; n >= 0; n--) {
    y32=Macros.SKP_SMLAWW(p[n],y32,x_Q16);
  }
  return y32;
}

Fixed version (ground truth):
/** 
 * Helper function for A2NLSF(..). Polynomial evaluation.
 * @param p Polynomial, QPoly
 * @param x Evaluation point, Q12
 * @param dd  Order
 * @return return the polynomial evaluation, in QPoly
 */
static int SKP_Silk_A2NLSF_eval_poly(int[] p,final int x,final int dd){
  int n;
  int x_Q16, y32;
  y32=p[dd];
  x_Q16=x << 4;
  for (n=dd - 1; n >= 0; n--) {
    y32=SKP_SMLAWW(p[n],y32,x_Q16);
  }
  return y32;
}
Program: 107582
Project: 107582
Buggy source:
/** 
 * Split signal into two decimated bands using first-order allpass filters.
 * @param in Input signal [N].
 * @param in_offset offset of valid data.
 * @param S State vector [2].
 * @param S_offset offset of valid data.
 * @param outL Low band [N/2].
 * @param outL_offset offset of valid data.
 * @param outH High band [N/2].
 * @param outH_offset offset of valid data.
 * @param scratch Scratch memory [3*N/2].
 * @param N Number of input samples.
 */
static void SKP_Silk_ana_filt_bank_1(short[] in,int in_offset,int[] S,int S_offset,short[] outL,int outL_offset,short[] outH,int outH_offset,int[] scratch,final int N){
  int k, N2=N >> 1;
  int in32, X, Y, out_1, out_2;
  for (k=0; k < N2; k++) {
    in32=in[in_offset + 2 * k] << 10;
    Y=in32 - S[S_offset + 0];
    X=Macros.SKP_SMLAWB(Y,Y,A_fb1_21[0]);
    out_1=S[S_offset + 0] + X;
    S[S_offset + 0]=in32 + X;
    in32=in[in_offset + 2 * k + 1] << 10;
    Y=in32 - S[S_offset + 1];
    X=Macros.SKP_SMULWB(Y,A_fb1_20[0]);
    out_2=S[S_offset + 1] + X;
    S[S_offset + 1]=in32 + X;
    outL[outL_offset + k]=(short)SigProcFIX.SKP_SAT16(SigProcFIX.SKP_RSHIFT_ROUND(out_2 + out_1,11));
    outH[outH_offset + k]=(short)SigProcFIX.SKP_SAT16(SigProcFIX.SKP_RSHIFT_ROUND(out_2 - out_1,11));
  }
}

Fixed version (ground truth):
/** 
 * Split signal into two decimated bands using first-order allpass filters.
 * @param in Input signal [N].
 * @param in_offset offset of valid data.
 * @param S State vector [2].
 * @param S_offset offset of valid data.
 * @param outL Low band [N/2].
 * @param outL_offset offset of valid data.
 * @param outH High band [N/2].
 * @param outH_offset offset of valid data.
 * @param scratch Scratch memory [3*N/2].
 * @param N Number of input samples.
 */
static void SKP_Silk_ana_filt_bank_1(short[] in,int in_offset,int[] S,int S_offset,short[] outL,int outL_offset,short[] outH,int outH_offset,int[] scratch,final int N){
  int k, N2=N >> 1;
  int in32, X, Y, out_1, out_2;
  for (k=0; k < N2; k++) {
    in32=in[in_offset + 2 * k] << 10;
    Y=in32 - S[S_offset + 0];
    X=SKP_SMLAWB(Y,Y,A_fb1_21[0]);
    out_1=S[S_offset + 0] + X;
    S[S_offset + 0]=in32 + X;
    in32=in[in_offset + 2 * k + 1] << 10;
    Y=in32 - S[S_offset + 1];
    X=SKP_SMULWB(Y,A_fb1_20[0]);
    out_2=S[S_offset + 1] + X;
    S[S_offset + 1]=in32 + X;
    outL[outL_offset + k]=(short)SigProcFIX.SKP_SAT16(SigProcFIX.SKP_RSHIFT_ROUND(out_2 + out_1,11));
    outH[outH_offset + k]=(short)SigProcFIX.SKP_SAT16(SigProcFIX.SKP_RSHIFT_ROUND(out_2 - out_1,11));
  }
}
Program: 107583
Project: 107583
Buggy source:
/** 
 * Second order ARMA filter Can handle slowly varying filter coefficients
 * @param in input signal
 * @param in_offset offset of valid data.
 * @param B MA coefficients, Q13 [3]
 * @param A AR coefficients, Q13 [2]
 * @param S state vector [2]
 * @param out output signal
 * @param out_offset offset of valid data.
 * @param len signal length
 */
static void SKP_Silk_biquad(short[] in,int in_offset,short[] B,short[] A,int[] S,short[] out,int out_offset,final int len){
  int k, in16;
  int A0_neg, A1_neg, S0, S1, out32, tmp32;
  S0=S[0];
  S1=S[1];
  A0_neg=-A[0];
  A1_neg=-A[1];
  for (k=0; k < len; k++) {
    in16=in[in_offset + k];
    out32=Macros.SKP_SMLABB(S0,in16,B[0]);
    S0=Macros.SKP_SMLABB(S1,in16,B[1]);
    S0+=(Macros.SKP_SMULWB(out32,A0_neg) << 3);
    S1=(Macros.SKP_SMULWB(out32,A1_neg) << 3);
    S1=Macros.SKP_SMLABB(S1,in16,B[2]);
    tmp32=SigProcFIX.SKP_RSHIFT_ROUND(out32,13) + 1;
    out[out_offset + k]=(short)SigProcFIX.SKP_SAT16(tmp32);
  }
  S[0]=S0;
  S[1]=S1;
}

Fixed version (ground truth):
/** 
 * Second order ARMA filter Can handle slowly varying filter coefficients
 * @param in input signal
 * @param in_offset offset of valid data.
 * @param B MA coefficients, Q13 [3]
 * @param A AR coefficients, Q13 [2]
 * @param S state vector [2]
 * @param out output signal
 * @param out_offset offset of valid data.
 * @param len signal length
 */
static void SKP_Silk_biquad(short[] in,int in_offset,short[] B,short[] A,int[] S,short[] out,int out_offset,final int len){
  int k, in16;
  int A0_neg, A1_neg, S0, S1, out32, tmp32;
  S0=S[0];
  S1=S[1];
  A0_neg=-A[0];
  A1_neg=-A[1];
  for (k=0; k < len; k++) {
    in16=in[in_offset + k];
    out32=SKP_SMLABB(S0,in16,B[0]);
    S0=SKP_SMLABB(S1,in16,B[1]);
    S0+=(SKP_SMULWB(out32,A0_neg) << 3);
    S1=(SKP_SMULWB(out32,A1_neg) << 3);
    S1=SKP_SMLABB(S1,in16,B[2]);
    tmp32=SigProcFIX.SKP_RSHIFT_ROUND(out32,13) + 1;
    out[out_offset + k]=(short)SigProcFIX.SKP_SAT16(tmp32);
  }
  S[0]=S0;
  S[1]=S1;
}
Program: 107584
Project: 107584
Buggy source:
/** 
 * Second order ARMA filter, alternative implementation.
 * @param in Input signal.
 * @param in_offset offset of valid data.
 * @param B_Q28 MA coefficients [3].
 * @param A_Q28 AR coefficients [2].
 * @param S State vector [2].
 * @param out Output signal.
 * @param out_offset offset of valid data.
 * @param len Signal length (must be even).
 */
static void SKP_Silk_biquad_alt(short[] in,int in_offset,int[] B_Q28,int[] A_Q28,int[] S,short[] out,int out_offset,final int len){
  int k;
  int inval, A0_U_Q28, A0_L_Q28, A1_U_Q28, A1_L_Q28, out32_Q14;
  A0_L_Q28=(-A_Q28[0]) & 0x00003FFF;
  A0_U_Q28=(-A_Q28[0]) >> 14;
  A1_L_Q28=(-A_Q28[1]) & 0x00003FFF;
  A1_U_Q28=(-A_Q28[1]) >> 14;
  for (k=0; k < len; k++) {
    inval=in[in_offset + k];
    out32_Q14=Macros.SKP_SMLAWB(S[0],B_Q28[0],inval) << 2;
    S[0]=S[1] + (Macros.SKP_SMULWB(out32_Q14,A0_L_Q28) >> 14);
    S[0]=Macros.SKP_SMLAWB(S[0],out32_Q14,A0_U_Q28);
    S[0]=Macros.SKP_SMLAWB(S[0],B_Q28[1],inval);
    S[1]=Macros.SKP_SMULWB(out32_Q14,A1_L_Q28) >> 14;
    S[1]=Macros.SKP_SMLAWB(S[1],out32_Q14,A1_U_Q28);
    S[1]=Macros.SKP_SMLAWB(S[1],B_Q28[2],inval);
    out[out_offset + k]=(short)SigProcFIX.SKP_SAT16((out32_Q14 >> 14) + 2);
  }
}

Fixed version (ground truth):
/** 
 * Second order ARMA filter, alternative implementation.
 * @param in Input signal.
 * @param in_offset offset of valid data.
 * @param B_Q28 MA coefficients [3].
 * @param A_Q28 AR coefficients [2].
 * @param S State vector [2].
 * @param out Output signal.
 * @param out_offset offset of valid data.
 * @param len Signal length (must be even).
 */
static void SKP_Silk_biquad_alt(short[] in,int in_offset,int[] B_Q28,int[] A_Q28,int[] S,short[] out,int out_offset,final int len){
  int k;
  int inval, A0_U_Q28, A0_L_Q28, A1_U_Q28, A1_L_Q28, out32_Q14;
  A0_L_Q28=(-A_Q28[0]) & 0x00003FFF;
  A0_U_Q28=(-A_Q28[0]) >> 14;
  A1_L_Q28=(-A_Q28[1]) & 0x00003FFF;
  A1_U_Q28=(-A_Q28[1]) >> 14;
  for (k=0; k < len; k++) {
    inval=in[in_offset + k];
    out32_Q14=SKP_SMLAWB(S[0],B_Q28[0],inval) << 2;
    S[0]=S[1] + (SKP_SMULWB(out32_Q14,A0_L_Q28) >> 14);
    S[0]=SKP_SMLAWB(S[0],out32_Q14,A0_U_Q28);
    S[0]=SKP_SMLAWB(S[0],B_Q28[1],inval);
    S[1]=SKP_SMULWB(out32_Q14,A1_L_Q28) >> 14;
    S[1]=SKP_SMLAWB(S[1],out32_Q14,A1_U_Q28);
    S[1]=SKP_SMLAWB(S[1],B_Q28[2],inval);
    out[out_offset + k]=(short)SigProcFIX.SKP_SAT16((out32_Q14 >> 14) + 2);
  }
}
Program: 107585
Project: 107585
Buggy source:
/** 
 * Chirp (bandwidth expand) LP AR filter.
 * @param ar AR filter to be expanded (without leading 1).
 * @param d Length of ar.
 * @param chirp_Q16  Chirp factor in Q16.
 */
static void SKP_Silk_bwexpander_32(int[] ar,final int d,int chirp_Q16){
  int i;
  int tmp_chirp_Q16;
  tmp_chirp_Q16=chirp_Q16;
  for (i=0; i < d - 1; i++) {
    ar[i]=Macros.SKP_SMULWW(ar[i],tmp_chirp_Q16);
    tmp_chirp_Q16=Macros.SKP_SMULWW(chirp_Q16,tmp_chirp_Q16);
  }
  ar[d - 1]=Macros.SKP_SMULWW(ar[d - 1],tmp_chirp_Q16);
}

Fixed version (ground truth):
/** 
 * Chirp (bandwidth expand) LP AR filter.
 * @param ar AR filter to be expanded (without leading 1).
 * @param d Length of ar.
 * @param chirp_Q16  Chirp factor in Q16.
 */
static void SKP_Silk_bwexpander_32(int[] ar,final int d,int chirp_Q16){
  int i;
  int tmp_chirp_Q16;
  tmp_chirp_Q16=chirp_Q16;
  for (i=0; i < d - 1; i++) {
    ar[i]=SKP_SMULWW(ar[i],tmp_chirp_Q16);
    tmp_chirp_Q16=SKP_SMULWW(chirp_Q16,tmp_chirp_Q16);
  }
  ar[d - 1]=SKP_SMULWW(ar[d - 1],tmp_chirp_Q16);
}
Program: 107587
Project: 107587
Buggy source:
/** 
 * Generates excitation for CNG LPC synthesis.
 * @param residual CNG residual signal Q0.
 * @param residual_offset offset of the valid data.
 * @param exc_buf_Q10 Random samples buffer Q10.
 * @param exc_buf_Q10_offset offset of the valid data.
 * @param Gain_Q16 Gain to apply
 * @param length Length
 * @param rand_seed Seed to random index generator
 */
static void SKP_Silk_CNG_exc(short residual[],int residual_offset,int exc_buf_Q10[],int exc_buf_Q10_offset,int Gain_Q16,int length,int[] rand_seed){
  int seed;
  int i, idx, exc_mask;
  exc_mask=Define.CNG_BUF_MASK_MAX;
  while (exc_mask > length) {
    exc_mask=(exc_mask >> 1);
  }
  seed=rand_seed[0];
  for (i=0; i < length; i++) {
    seed=SigProcFIX.SKP_RAND(seed);
    idx=((seed >> 24) & exc_mask);
    Typedef.SKP_assert(idx >= 0);
    Typedef.SKP_assert(idx <= Define.CNG_BUF_MASK_MAX);
    residual[residual_offset + i]=(short)SigProcFIX.SKP_SAT16(SigProcFIX.SKP_RSHIFT_ROUND(Macros.SKP_SMULWW(exc_buf_Q10[idx],Gain_Q16),10));
  }
  rand_seed[0]=seed;
}

Fixed version (ground truth):
/** 
 * Generates excitation for CNG LPC synthesis.
 * @param residual CNG residual signal Q0.
 * @param residual_offset offset of the valid data.
 * @param exc_buf_Q10 Random samples buffer Q10.
 * @param exc_buf_Q10_offset offset of the valid data.
 * @param Gain_Q16 Gain to apply
 * @param length Length
 * @param rand_seed Seed to random index generator
 */
static void SKP_Silk_CNG_exc(short residual[],int residual_offset,int exc_buf_Q10[],int exc_buf_Q10_offset,int Gain_Q16,int length,int[] rand_seed){
  int seed;
  int i, idx, exc_mask;
  exc_mask=CNG_BUF_MASK_MAX;
  while (exc_mask > length) {
    exc_mask=(exc_mask >> 1);
  }
  seed=rand_seed[0];
  for (i=0; i < length; i++) {
    seed=SigProcFIX.SKP_RAND(seed);
    idx=((seed >> 24) & exc_mask);
    SKP_assert(idx >= 0);
    SKP_assert(idx <= CNG_BUF_MASK_MAX);
    residual[residual_offset + i]=(short)SigProcFIX.SKP_SAT16(SigProcFIX.SKP_RSHIFT_ROUND(SKP_SMULWW(exc_buf_Q10[idx],Gain_Q16),10));
  }
  rand_seed[0]=seed;
}
Program: 107588
Project: 107588
Buggy source:
/** 
 * Reset CNG.
 * @param psDec Decoder state.
 */
static void SKP_Silk_CNG_Reset(SKP_Silk_decoder_state psDec){
  int i, NLSF_step_Q15, NLSF_acc_Q15;
  NLSF_step_Q15=(Typedef.SKP_int16_MAX / (psDec.LPC_order + 1));
  NLSF_acc_Q15=0;
  for (i=0; i < psDec.LPC_order; i++) {
    NLSF_acc_Q15+=NLSF_step_Q15;
    psDec.sCNG.CNG_smth_NLSF_Q15[i]=NLSF_acc_Q15;
  }
  psDec.sCNG.CNG_smth_Gain_Q16=0;
  psDec.sCNG.rand_seed=3176576;
}

Fixed version (ground truth):
/** 
 * Reset CNG.
 * @param psDec Decoder state.
 */
static void SKP_Silk_CNG_Reset(SKP_Silk_decoder_state psDec){
  int i, NLSF_step_Q15, NLSF_acc_Q15;
  NLSF_step_Q15=(SKP_int16_MAX / (psDec.LPC_order + 1));
  NLSF_acc_Q15=0;
  for (i=0; i < psDec.LPC_order; i++) {
    NLSF_acc_Q15+=NLSF_step_Q15;
    psDec.sCNG.CNG_smth_NLSF_Q15[i]=NLSF_acc_Q15;
  }
  psDec.sCNG.CNG_smth_Gain_Q16=0;
  psDec.sCNG.rand_seed=3176576;
}