From 24570f6dabef2923280e38894627244954c328a1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 27 Apr 2022 01:52:37 +0100 Subject: Prefer std::copy over memcpy, handles case of null data ptr when empty --- netfs/fuse/fuseFiles.cpp | 2 +- netfs/unittests/testCore.cpp | 3 ++- 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(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 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 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); -- cgit v1.2.3