|
|
ad2d76 |
From 63d66e7a3356da4bca77f521fd93df7cdf09b41a Mon Sep 17 00:00:00 2001
|
|
|
ad2d76 |
From: Ondrej Kozina <okozina@redhat.com>
|
|
|
ad2d76 |
Date: Tue, 19 Jun 2018 15:10:33 +0200
|
|
|
ad2d76 |
Subject: [PATCH 3/4] Fix write_blockwise on short files.
|
|
|
ad2d76 |
|
|
|
ad2d76 |
see unit test write_blockwise(length=2097153, bsize=4096), on x86
|
|
|
ad2d76 |
with original test file size=2097152.
|
|
|
ad2d76 |
|
|
|
ad2d76 |
The test is trying to write_blockwise 1 more byte than actual file
|
|
|
ad2d76 |
size.
|
|
|
ad2d76 |
---
|
|
|
ad2d76 |
lib/utils_io.c | 8 +++-----
|
|
|
ad2d76 |
1 file changed, 3 insertions(+), 5 deletions(-)
|
|
|
ad2d76 |
|
|
|
ad2d76 |
diff --git a/lib/utils_io.c b/lib/utils_io.c
|
|
|
ad2d76 |
index 8336b18..e0c2381 100644
|
|
|
ad2d76 |
--- a/lib/utils_io.c
|
|
|
ad2d76 |
+++ b/lib/utils_io.c
|
|
|
ad2d76 |
@@ -105,15 +105,13 @@ ssize_t write_blockwise(int fd, size_t bsize, size_t alignment,
|
|
|
ad2d76 |
if (hangover) {
|
|
|
ad2d76 |
if (posix_memalign(&hangover_buf, alignment, bsize))
|
|
|
ad2d76 |
goto out;
|
|
|
ad2d76 |
+ memset(hangover_buf, 0, bsize);
|
|
|
ad2d76 |
|
|
|
ad2d76 |
r = read_buffer(fd, hangover_buf, bsize);
|
|
|
ad2d76 |
- if (r < 0 || r < (ssize_t)hangover)
|
|
|
ad2d76 |
+ if (r < 0)
|
|
|
ad2d76 |
goto out;
|
|
|
ad2d76 |
|
|
|
ad2d76 |
- if (r < (ssize_t)bsize)
|
|
|
ad2d76 |
- bsize = r;
|
|
|
ad2d76 |
-
|
|
|
ad2d76 |
- if (lseek(fd, -(off_t)bsize, SEEK_CUR) < 0)
|
|
|
ad2d76 |
+ if (lseek(fd, -(off_t)r, SEEK_CUR) < 0)
|
|
|
ad2d76 |
goto out;
|
|
|
ad2d76 |
|
|
|
ad2d76 |
memcpy(hangover_buf, (char*)buf + solid, hangover);
|
|
|
ad2d76 |
--
|
|
|
ad2d76 |
1.8.3.1
|
|
|
ad2d76 |
|