1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-14 10:13:05 +02:00

Fix EOF behavior of ioReadSmall() to match ioRead().

If the buffer was not full at EOF then ioReadSmall() would get stuck in an infinite loop. Instead, return on EOF even if the buffer is not full.

This is not an issue in released versions since ioReadSmall() is not being used.

Also fix a comment typo.
This commit is contained in:
David Steele 2021-08-18 09:32:20 -04:00
parent 4fb6384f10
commit 9a6afe3fc1
2 changed files with 3 additions and 2 deletions

View File

@ -252,7 +252,7 @@ ioReadSmall(IoRead *this, Buffer *buffer)
{ {
ioReadInternal(this, buffer, true); ioReadInternal(this, buffer, true);
} }
// Else read as much data as is available. If is not enough we will try again later. // Else read as much data as is available. If it is not enough we will try again later.
else else
{ {
// Clear the internal output buffer since all data was copied already // Clear the internal output buffer since all data was copied already
@ -263,7 +263,7 @@ ioReadSmall(IoRead *this, Buffer *buffer)
} }
} }
} }
while (!bufFull(buffer)); while (!bufFull(buffer) && !ioReadEof(this));
FUNCTION_TEST_RETURN(outputRemains - bufRemains(buffer)); FUNCTION_TEST_RETURN(outputRemains - bufRemains(buffer));
} }

View File

@ -440,6 +440,7 @@ testRun(void)
// Nothing left to read // Nothing left to read
TEST_ERROR(ioReadLine(read), FileReadError, "unexpected eof while reading line"); TEST_ERROR(ioReadLine(read), FileReadError, "unexpected eof while reading line");
TEST_RESULT_UINT(ioRead(read, buffer), 0, "read buffer"); TEST_RESULT_UINT(ioRead(read, buffer), 0, "read buffer");
TEST_RESULT_UINT(ioReadSmall(read, bufNew(55)), 0, "read buffer");
// Error if buffer is full and there is no linefeed // Error if buffer is full and there is no linefeed
ioBufferSizeSet(10); ioBufferSizeSet(10);