pgbackrest.git / summary / log / commit / refs
commit 9a6afe3fc16fcb0685613308e47c19f6b11e7e35
Author: David Steele <david@pgmasters.net>
Date: Wed Aug 18 13:32:20 2021 +0000
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.
src/common/io/read.c | 4 ++--
test/src/module/common/ioTest.c | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/common/io/read.c b/src/common/io/read.c
index f3d0eb403..1ef169f7b 100644
--- a/src/common/io/read.c
+++ b/src/common/io/read.c
@@ -252,7 +252,7 @@ ioReadSmall(IoRead *this, Buffer *buffer)
{
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
{
// 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));
}
diff --git a/test/src/module/common/ioTest.c b/test/src/module/common/ioTest.c
index 2e3df6af5..38b149825 100644
--- a/test/src/module/common/ioTest.c
+++ b/test/src/module/common/ioTest.c
@@ -440,6 +440,7 @@ testRun(void)
// Nothing left to read
TEST_ERROR(ioReadLine(read), FileReadError, "unexpected eof while reading line");
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
ioBufferSizeSet(10);
[parent: 4fb6384f10f6]