Program: 56105
Project: 56105
Buggy source:
/** 
 * Fills the given list with collections of buffers for channels. The list will contain as many collections as the parameter <code>numReaders</code> specifies.
 * @param target The list into which the lists with buffers for the channels are put.
 * @param totalReadMemory The total amount of memory to be divided among the channels.
 * @param numChannels The number of channels for which to allocate buffers.
 * @return A list with all memory segments that were allocated.
 * @throws MemoryAllocationException Thrown, if the specified memory is insufficient to merge the channelsor if the memory manager could not provide the requested memory.
 */
protected final List<MemorySegment> getSegmentsForReaders(List<List<MemorySegment>> target,long totalReadMemory,int numChannels) throws MemoryAllocationException {
  final long ioMemoryPerChannel=totalReadMemory / numChannels;
  final int numBuffers=ioMemoryPerChannel < 2 * MIN_IO_BUFFER_SIZE ? 1 : ioMemoryPerChannel < 2 * MAX_IO_BUFFER_SIZE ? 2 : (int)(ioMemoryPerChannel / MAX_IO_BUFFER_SIZE);
  final long bufferSize=(ioMemoryPerChannel / numBuffers) & BUFFER_ALIGNMENT_MASK;
  final List<MemorySegment> memorySegments=this.memoryManager.allocate(this.parent,bufferSize * numBuffers * numChannels,numBuffers * numChannels,MIN_IO_BUFFER_SIZE);
  for (int i=0, buffer=0; i < numChannels - 1; i++) {
    List<MemorySegment> segs=new ArrayList<MemorySegment>(numBuffers);
    target.add(segs);
    for (int k=0; k < numBuffers; k++, buffer++) {
      segs.add(memorySegments.get(buffer));
    }
  }
  List<MemorySegment> segsForLast=new ArrayList<MemorySegment>(numBuffers);
  target.add(segsForLast);
  for (int i=(numChannels - 1) * numBuffers; i < memorySegments.size(); i++) {
    segsForLast.add(memorySegments.get(i));
  }
  return memorySegments;
}

Fixed version (ground truth):
/** 
 * Fills the given list with collections of buffers for channels. The list will contain as many collections as the parameter <code>numReaders</code> specifies.
 * @param target The list into which the lists with buffers for the channels are put.
 * @param totalReadMemory The total amount of memory to be divided among the channels.
 * @param numChannels The number of channels for which to allocate buffers. Must not be zero.
 * @return A list with all memory segments that were allocated.
 * @throws MemoryAllocationException Thrown, if the specified memory is insufficient to merge the channelsor if the memory manager could not provide the requested memory.
 */
protected final List<MemorySegment> getSegmentsForReaders(List<List<MemorySegment>> target,long totalReadMemory,int numChannels) throws MemoryAllocationException {
  final long ioMemoryPerChannel=totalReadMemory / numChannels;
  final int numBuffers=ioMemoryPerChannel < 2 * MIN_IO_BUFFER_SIZE ? 1 : ioMemoryPerChannel < 2 * MAX_IO_BUFFER_SIZE ? 2 : (int)(ioMemoryPerChannel / MAX_IO_BUFFER_SIZE);
  final long bufferSize=(ioMemoryPerChannel / numBuffers) & BUFFER_ALIGNMENT_MASK;
  final List<MemorySegment> memorySegments=this.memoryManager.allocate(this.parent,bufferSize * numBuffers * numChannels,numBuffers * numChannels,MIN_IO_BUFFER_SIZE);
  for (int i=0, buffer=0; i < numChannels - 1; i++) {
    List<MemorySegment> segs=new ArrayList<MemorySegment>(numBuffers);
    target.add(segs);
    for (int k=0; k < numBuffers; k++, buffer++) {
      segs.add(memorySegments.get(buffer));
    }
  }
  List<MemorySegment> segsForLast=new ArrayList<MemorySegment>(numBuffers);
  target.add(segsForLast);
  for (int i=(numChannels - 1) * numBuffers; i < memorySegments.size(); i++) {
    segsForLast.add(memorySegments.get(i));
  }
  return memorySegments;
}