Potential bug in IDHAMemoryXferBytes.cpp
Not 100% sure, but I think there is a small 'off by one' bug in IDHAMemoryXferBytes.cpp.
It's possible it is not causing issues - it all depends on what the calling code does with the class.
I think
pnum > numLeftInBuffer
should really be
pnum >= numLeftInBuffer
otherwise the routine does not flag EOF when we happen to request the exact number of remaining bytes.
See line with comment before it:
```
...
uint32 IDHAMemoryXferBytes::Read(void* buffer, uint32 pnum)
{
uint32 numToTransfer = 0;
do
{
if (buffer == nil)
{
ASSERT_FAIL("buffer is nil!");
break;
}
uint32 numLeftInBuffer = this->fCountBytesStored - this->fAbsolutePositionInBuffer;
// SHOULD THIS NOT BE `pnum >= numLeftInBuffer`?
// If we exhaust the buffer exactly, we are also at EOF
if (pnum > numLeftInBuffer)
{
numToTransfer = numLeftInBuffer;
fStreamState = kStreamStateEOF;
}
else
{
numToTransfer = pnum;
}
if (numToTransfer > 0)
memcpy(buffer, fMyBuffer + fAbsolutePositionInBuffer, numToTransfer);
fAbsolutePositionInBuffer += numToTransfer;
} while (false);
return numToTransfer;
}
...
```
1
vote
Kris Coppieters
shared this idea