summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-04-27 01:52:37 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-04-27 01:52:37 +0100
commit24570f6dabef2923280e38894627244954c328a1 (patch)
tree23b45fb24f2279611ddeced84997010b5ded7e18
parentHandle async write errors (diff)
downloadnetfs-24570f6dabef2923280e38894627244954c328a1.tar.bz2
netfs-24570f6dabef2923280e38894627244954c328a1.tar.xz
netfs-24570f6dabef2923280e38894627244954c328a1.zip
Prefer std::copy over memcpy, handles case of null data ptr when empty
-rw-r--r--netfs/fuse/fuseFiles.cpp2
-rw-r--r--netfs/unittests/testCore.cpp3
2 files changed, 3 insertions, 2 deletions
diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp
index f08c1dd..d2aae51 100644
--- a/netfs/fuse/fuseFiles.cpp
+++ b/netfs/fuse/fuseFiles.cpp
@@ -154,7 +154,7 @@ namespace NetFS {
{
try {
auto cpy = [buf](const auto && data) -> int {
- memcpy(buf, &data.front(), data.size());
+ std::copy(data.begin(), data.end(), buf);
return safe {data.size()};
};
auto of = getProxy<OpenFilePtr>(fi->fh);
diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp
index 5e7e65e..a6a74d5 100644
--- a/netfs/unittests/testCore.cpp
+++ b/netfs/unittests/testCore.cpp
@@ -260,7 +260,9 @@ BOOST_AUTO_TEST_CASE(files)
BOOST_REQUIRE_EQUAL(fuse->release("/test", &fi), -EBADF);
BOOST_REQUIRE_EQUAL(fuse->create("/test", 0600, &fi), -EEXIST);
+ std::array<char, 11> buf {};
BOOST_REQUIRE_EQUAL(fuse->open("/test", &fi), 0);
+ BOOST_REQUIRE_EQUAL(fuse->read("/test", buf.data(), 0, 0, &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->write("/test", "some test buffer", 16, 0, &fi), 16);
BOOST_REQUIRE_EQUAL(fuse->flush("/test", &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->getattr("/test", &st, nullptr), 0);
@@ -276,7 +278,6 @@ BOOST_AUTO_TEST_CASE(files)
BOOST_REQUIRE_EQUAL(fuse->write("/test2", "BUFFER some", 11, 10, &fi), 11);
BOOST_REQUIRE_EQUAL(fuse->getattr("/test2", &st2, &fi), 0);
BOOST_REQUIRE_EQUAL(st2.st_size, 21);
- std::array<char, 11> buf {};
BOOST_REQUIRE_EQUAL(fuse->read("/test2", buf.data(), 10, 5, &fi), 10);
BOOST_REQUIRE_EQUAL(buf, "test BUFFE");
BOOST_REQUIRE_EQUAL(fuse->truncate("/test2", 11, &fi), 0);