diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-08-25 16:28:29 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-08-25 17:58:05 -0700 |
commit | 288b91bc5909208e5b5e69511f0169c3126c7b78 (patch) | |
tree | 124bf885266d52b24798bdc127f9df0d2a76374e | |
parent | 7ec146c05489f43dddb1b7af948a193c1cf0a9d1 (diff) | |
parent | e8aa00b76fb9d19714a9d05dc6dd09ae10c5250e (diff) | |
download | tmwa-288b91bc5909208e5b5e69511f0169c3126c7b78.tar.gz tmwa-288b91bc5909208e5b5e69511f0169c3126c7b78.tar.bz2 tmwa-288b91bc5909208e5b5e69511f0169c3126c7b78.tar.xz tmwa-288b91bc5909208e5b5e69511f0169c3126c7b78.zip |
Merge branch 'hotfix'
Conflicts:
CHANGELOG
src/io/write_test.cpp
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | src/io/write.cpp | 1 | ||||
-rw-r--r-- | src/io/write_test.cpp | 35 |
3 files changed, 37 insertions, 1 deletions
@@ -16,6 +16,8 @@ v14.6.30: - drop gcc 4.6 support - completely remove flex/bison dependency - fix duplication in npctalk +v14.4.20: + - fix potential file corruption with partial writes v14.4.19: - emergency backport of security fix, since v14.7.1 is too buggy v14.4.18: diff --git a/src/io/write.cpp b/src/io/write.cpp index 833b173..5359c7a 100644 --- a/src/io/write.cpp +++ b/src/io/write.cpp @@ -97,6 +97,7 @@ namespace io dat += rv; len -= rv; } + std::copy(dat, dat + len, buf); buflen = len; maybe_linebuffered: diff --git a/src/io/write_test.cpp b/src/io/write_test.cpp index 2347e7e..405d28a 100644 --- a/src/io/write_test.cpp +++ b/src/io/write_test.cpp @@ -28,7 +28,7 @@ #include "../strings/xstring.hpp" #include "../strings/literal.hpp" -#include "../poison.hpp" +//#include "../poison.hpp" namespace tmwa @@ -104,4 +104,37 @@ TEST(io, write2) EXPECT_TRUE(wf.close()); EXPECT_EQ("XXX"_s, pw.slurp()); } + +TEST(io, write3) +{ + // TODO see if it's possible to get the real value + constexpr size_t PIPE_CAPACITY = 65536; + char buf[PIPE_CAPACITY]; + + PipeWriter pw(false); + io::WriteFile& wf = pw.wf; + + memset(buf, 'a', sizeof(buf)); + wf.really_put(buf, 1); + EXPECT_EQ(""_s, pw.slurp()); + + memset(buf, 'b', sizeof(buf)); + wf.really_put(buf, sizeof(buf)); + + // write 1 + PIPE_CAPACITY + // read 1 + N + (PIPE_CAPACITY - N) + size_t remaining; + { + AString a = pw.slurp(); + XString x = a.xslice_t(1); + EXPECT_EQ(a.front(), 'a'); + EXPECT_EQ(x.front(), 'b'); + EXPECT_EQ(x.back(), 'b'); + EXPECT_EQ(x, XString(buf, buf + x.size(), nullptr)); + remaining = sizeof(buf) - x.size(); + } + + EXPECT_TRUE(wf.close()); + EXPECT_EQ(pw.slurp(), XString(buf, buf + remaining, nullptr)); +} } // namespace tmwa |