handle case to avoid memcpy when staticmemory IO pool gives same buffer

This commit is contained in:
Jacob Barthelmeh
2019-11-07 11:36:20 -07:00
parent 0fe5d40507
commit fd3e4abb46

View File

@ -7651,6 +7651,16 @@ static WC_INLINE int GrowOutputBuffer(WOLFSSL* ssl, int size)
tmp += align - hdrSz;
#endif
#ifdef WOLFSSL_STATIC_MEMORY
/* can be from IO memory pool which does not need copy if same buffer */
if (ssl->buffers.outputBuffer.length &&
tmp == ssl->buffers.outputBuffer.buffer) {
ssl->buffers.outputBuffer.bufferSize =
size + ssl->buffers.outputBuffer.length;
return 0;
}
#endif
if (ssl->buffers.outputBuffer.length)
XMEMCPY(tmp, ssl->buffers.outputBuffer.buffer,
ssl->buffers.outputBuffer.length);
@ -7715,6 +7725,16 @@ int GrowInputBuffer(WOLFSSL* ssl, int size, int usedLength)
tmp += align - hdrSz;
#endif
#ifdef WOLFSSL_STATIC_MEMORY
/* can be from IO memory pool which does not need copy if same buffer */
if (usedLength && tmp == ssl->buffers.inputBuffer.buffer) {
ssl->buffers.inputBuffer.bufferSize = size + usedLength;
ssl->buffers.inputBuffer.idx = 0;
ssl->buffers.inputBuffer.length = usedLength;
return 0;
}
#endif
if (usedLength)
XMEMCPY(tmp, ssl->buffers.inputBuffer.buffer +
ssl->buffers.inputBuffer.idx, usedLength);