From 9551a7d0532f257da575fa9d92fe110bedc2377d Mon Sep 17 00:00:00 2001 From: Victor Smirnov <53015676+vityaman@users.noreply.github.com> Date: Sat, 6 Sep 2025 10:41:36 +0300 Subject: [PATCH 1/2] Fix issues/13 Signed-off-by: Victor Smirnov <53015676+vityaman@users.noreply.github.com> --- lab/vtpc/test/lib/file.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lab/vtpc/test/lib/file.cpp b/lab/vtpc/test/lib/file.cpp index dff8ed9..01e57e4 100644 --- a/lab/vtpc/test/lib/file.cpp +++ b/lab/vtpc/test/lib/file.cpp @@ -44,7 +44,9 @@ template void robust_do(A action, int fd, auto buf, size_t count) { size_t total = 0; while (total < count) { - const ssize_t local = action(fd, buf, count); + const size_t tail_count = count - total; + auto* tail_buf = reinterpret_cast(buf) + total; + const ssize_t local = action(fd, tail_buf, tail_count); if (local < 0) { throw vt::file_exception(local) << "failed to read/write " << count << " bytes from file with fd " From 6a98db3865a9e5d37dce94eba6a4bca7200b65a6 Mon Sep 17 00:00:00 2001 From: vityaman Date: Sat, 6 Sep 2025 07:48:43 +0000 Subject: [PATCH 2/2] cast --- lab/vtpc/test/lib/file.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lab/vtpc/test/lib/file.cpp b/lab/vtpc/test/lib/file.cpp index 01e57e4..c2d7f64 100644 --- a/lab/vtpc/test/lib/file.cpp +++ b/lab/vtpc/test/lib/file.cpp @@ -40,12 +40,17 @@ struct io { std::function fsync; }; -template -void robust_do(A action, int fd, auto buf, size_t count) { +template +void robust_do(A action, int fd, T* buf, size_t count) { + using B = std::conditional_t< + std::is_const_v>, + const char, + char>; + size_t total = 0; while (total < count) { const size_t tail_count = count - total; - auto* tail_buf = reinterpret_cast(buf) + total; + B* tail_buf = reinterpret_cast(buf) + total; // NOLINT const ssize_t local = action(fd, tail_buf, tail_count); if (local < 0) { throw vt::file_exception(local)