From 353723ea77e1144e6cb97e390a23a2ebc6cf3587 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 8 Mar 2018 08:35:36 +1300 Subject: [PATCH] Fix EOF handling in BufferedFile::read() Tell io_pread() we need at least one byte so it will handle EOF for us. Previously we read the byte one after the end of the buffer if we tried to read past EOF. --- xapian-core/backends/honey/honey_table.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xapian-core/backends/honey/honey_table.h b/xapian-core/backends/honey/honey_table.h index 42396b81a..70807bf8b 100644 --- a/xapian-core/backends/honey/honey_table.h +++ b/xapian-core/backends/honey/honey_table.h @@ -228,7 +228,9 @@ class BufferedFile { int read() const { #if 1 if (buf_end == 0) { - size_t r = io_pread(fd, buf, sizeof(buf), pos); + // The buffer is currently empty, so we need to read at least one + // byte. + size_t r = io_pread(fd, buf, sizeof(buf), pos, 1); if (r < sizeof(buf)) { memmove(buf + sizeof(buf) - r, buf, r); } -- 2.11.4.GIT