summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2019-03-31 19:11:31 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2019-03-31 19:11:31 +0100
commite0e9036430febb247a88afb5f567092421595a77 (patch)
tree0a58f60ce9d7c0c342cb1e97907f82da51654516
parentExplicitly disable checker for generated code (diff)
downloadnetfs-e0e9036430febb247a88afb5f567092421595a77.tar.bz2
netfs-e0e9036430febb247a88afb5f567092421595a77.tar.xz
netfs-e0e9036430febb247a88afb5f567092421595a77.zip
First round of clang tidy changes
-rw-r--r--Jamroot.jam5
-rw-r--r--netfs/daemon/daemon.cpp8
-rw-r--r--netfs/daemon/daemon.h1
-rw-r--r--netfs/daemon/daemonDirectory.cpp6
-rw-r--r--netfs/daemon/daemonDirectory.h1
-rw-r--r--netfs/daemon/daemonFile.cpp6
-rw-r--r--netfs/daemon/daemonFile.h1
-rw-r--r--netfs/daemon/daemonService.cpp2
-rw-r--r--netfs/daemon/daemonVolume.cpp23
-rw-r--r--netfs/daemon/daemonVolume.h1
-rw-r--r--netfs/fuse/fuseApp.cpp18
-rw-r--r--netfs/fuse/fuseApp.h6
-rw-r--r--netfs/fuse/fuseAppBase.cpp29
-rw-r--r--netfs/fuse/fuseAppBase.h3
-rw-r--r--netfs/fuse/fuseDirs.cpp14
-rw-r--r--netfs/fuse/fuseFiles.cpp8
-rw-r--r--netfs/fuse/fuseMisc.cpp3
-rw-r--r--netfs/fuse/netfs.cpp5
-rw-r--r--netfs/ice/entryResolver.h5
-rw-r--r--netfs/ice/typeConverter.cpp20
-rw-r--r--netfs/lib/entCache.cpp34
-rw-r--r--netfs/lib/entCache.h23
-rw-r--r--netfs/unittests/Jamfile.jam5
-rw-r--r--netfs/unittests/mockDaemon.cpp10
-rw-r--r--netfs/unittests/mockDaemon.h4
-rw-r--r--netfs/unittests/mockFuse.cpp22
-rw-r--r--netfs/unittests/mockFuse.h7
-rw-r--r--netfs/unittests/testCore.cpp139
-rw-r--r--netfs/unittests/testEdgeCases.cpp4
29 files changed, 183 insertions, 230 deletions
diff --git a/Jamroot.jam b/Jamroot.jam
index 0edd310..8677573 100644
--- a/Jamroot.jam
+++ b/Jamroot.jam
@@ -16,6 +16,11 @@ project
<variant>debug:<cxxflags>"-W -Wall -Werror -Wextra"
<variant>coverage:<cxxflags>"--coverage"
<variant>coverage:<linkflags>"--coverage"
+ <toolset>tidy:<checkxx>boost-*
+ <toolset>tidy:<checkxx>bugprone-*
+ <toolset>tidy:<checkxx>clang-*
+ <toolset>tidy:<checkxx>misc-*
+ <toolset>tidy:<checkxx>modernize-*
;
build-project netfs ;
diff --git a/netfs/daemon/daemon.cpp b/netfs/daemon/daemon.cpp
index 27dfbb9..2962ede 100644
--- a/netfs/daemon/daemon.cpp
+++ b/netfs/daemon/daemon.cpp
@@ -7,10 +7,6 @@
#include <sys/stat.h>
#include <safeMapFind.h>
-NetFSDaemon::NetFSDaemon()
-{
-}
-
NetFSDaemon::~NetFSDaemon()
{
if (adapter) {
@@ -24,8 +20,8 @@ NetFSDaemon::hostname()
auto props = ic->getProperties();
auto hostNameOverride = props->getProperty("NetFSD.HostNameOverride");
if (hostNameOverride.empty()) {
- char buf[128];
- gethostname(buf, sizeof(buf));
+ std::string buf(128, 0);
+ gethostname(buf.data(), buf.size());
return buf;
}
return hostNameOverride;
diff --git a/netfs/daemon/daemon.h b/netfs/daemon/daemon.h
index 57e2023..bc12973 100644
--- a/netfs/daemon/daemon.h
+++ b/netfs/daemon/daemon.h
@@ -9,7 +9,6 @@
class DLL_PUBLIC NetFSDaemon : public IceBox::Service {
public:
- NetFSDaemon();
virtual ~NetFSDaemon();
virtual void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&) override;
diff --git a/netfs/daemon/daemonDirectory.cpp b/netfs/daemon/daemonDirectory.cpp
index b03bd1f..44aa765 100644
--- a/netfs/daemon/daemonDirectory.cpp
+++ b/netfs/daemon/daemonDirectory.cpp
@@ -1,6 +1,6 @@
#include <Ice/ObjectAdapter.h>
#include <dirent.h>
-#include <errno.h>
+#include <cerrno>
#include <map>
#include <sys/stat.h>
#include <sys/types.h>
@@ -13,10 +13,6 @@ DirectoryServer::DirectoryServer(DIR * d, EntryTypeConverter & t) :
{
}
-DirectoryServer::~DirectoryServer()
-{
-}
-
void
DirectoryServer::close(const Ice::Current & ice)
{
diff --git a/netfs/daemon/daemonDirectory.h b/netfs/daemon/daemonDirectory.h
index 5e549fe..b4da8f2 100644
--- a/netfs/daemon/daemonDirectory.h
+++ b/netfs/daemon/daemonDirectory.h
@@ -8,7 +8,6 @@
class DirectoryServer : public NetFS::DirectoryV2, EntryTypeConverter {
public:
DirectoryServer(DIR * od, EntryTypeConverter &);
- virtual ~DirectoryServer();
virtual void close(const Ice::Current&) override;
virtual NetFS::NameList readdir(const Ice::Current&) override;
diff --git a/netfs/daemon/daemonFile.cpp b/netfs/daemon/daemonFile.cpp
index 0df3c2a..1113904 100644
--- a/netfs/daemon/daemonFile.cpp
+++ b/netfs/daemon/daemonFile.cpp
@@ -1,5 +1,5 @@
#include <Ice/ObjectAdapter.h>
-#include <errno.h>
+#include <cerrno>
#include <map>
#include <fcntl.h>
#include <typeConverter.h>
@@ -13,10 +13,6 @@ FileServer::FileServer(int f, EntryTypeConverter & t) :
{
}
-FileServer::~FileServer()
-{
-}
-
void
FileServer::ftruncate(const NetFS::ReqEnv re, Ice::Long size, const Ice::Current&)
{
diff --git a/netfs/daemon/daemonFile.h b/netfs/daemon/daemonFile.h
index 9a01abf..ee4ae7d 100644
--- a/netfs/daemon/daemonFile.h
+++ b/netfs/daemon/daemonFile.h
@@ -7,7 +7,6 @@
class FileServer : public NetFS::File, EntryTypeConverter {
public:
FileServer(int fd, EntryTypeConverter &);
- virtual ~FileServer();
virtual void close(const Ice::Current&) override;
virtual void ftruncate(const NetFS::ReqEnv, Ice::Long size, const Ice::Current&) override;
diff --git a/netfs/daemon/daemonService.cpp b/netfs/daemon/daemonService.cpp
index a516cb2..30dac0a 100644
--- a/netfs/daemon/daemonService.cpp
+++ b/netfs/daemon/daemonService.cpp
@@ -4,7 +4,7 @@
#include <safeMapFind.h>
ServiceServer::ServiceServer(NetFS::Daemon::ConfigurationPtr c) :
- config(c)
+ config(std::move(c))
{
}
diff --git a/netfs/daemon/daemonVolume.cpp b/netfs/daemon/daemonVolume.cpp
index 1a3680f..fd2f895 100644
--- a/netfs/daemon/daemonVolume.cpp
+++ b/netfs/daemon/daemonVolume.cpp
@@ -1,9 +1,9 @@
#include <Ice/ObjectAdapter.h>
-#include <errno.h>
+#include <cerrno>
#include <map>
#include <unistd.h>
#include <sys/stat.h>
-#include <limits.h>
+#include <climits>
#include <fcntl.h>
#include "daemonVolume.h"
#include "daemonFile.h"
@@ -23,10 +23,6 @@ VolumeServer::VolumeServer(const std::filesystem::path & r, const EntCache<User>
{
}
-VolumeServer::~VolumeServer()
-{
-}
-
void
VolumeServer::disconnect(const Ice::Current & ice)
{
@@ -135,14 +131,15 @@ VolumeServer::readlink(const NetFS::ReqEnv re, const std::string path, const Ice
{
ModeCheck mc(re, root, userLookup, groupLookup);
errno = 0;
- char buf[PATH_MAX];
+ std::string buf(PATH_MAX, 0);
std::filesystem::path p(resolvePath(std::move(path)));
mc.AssertRead(p);
- ssize_t rc = ::readlink(p.c_str(), buf, PATH_MAX);
+ ssize_t rc = ::readlink(p.c_str(), buf.data(), PATH_MAX);
if (rc == -1) {
throw NetFS::SystemError(errno);
}
- return std::string(buf, rc);
+ buf.resize(rc);
+ return buf;
}
void
@@ -175,14 +172,10 @@ VolumeServer::utimens(const NetFS::ReqEnv re, const std::string path,
{
ModeCheck mc(re, root, userLookup, groupLookup);
errno = 0;
- struct timespec times[2];
- times[0].tv_sec = s0;
- times[0].tv_nsec = ns0;
- times[1].tv_sec = s1;
- times[1].tv_nsec = ns1;
+ std::array<struct timespec, 2> times { { { s0, ns0 }, { s1, ns1 } } };
std::filesystem::path p(resolvePath(std::move(path)));
mc.AssertWrite(p);
- if (::utimensat(0, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) {
+ if (::utimensat(0, p.c_str(), times.data(), AT_SYMLINK_NOFOLLOW) != 0) {
throw NetFS::SystemError(errno);
}
}
diff --git a/netfs/daemon/daemonVolume.h b/netfs/daemon/daemonVolume.h
index 6e29893..5087654 100644
--- a/netfs/daemon/daemonVolume.h
+++ b/netfs/daemon/daemonVolume.h
@@ -10,7 +10,6 @@
class VolumeServer : public NetFS::Volume {
public:
VolumeServer(const std::filesystem::path & root, const EntCache<User> &, const EntCache<Group> &);
- virtual ~VolumeServer();
virtual NetFS::DirectoryPrxPtr opendir(const NetFS::ReqEnv, const std::string path, const Ice::Current&) override;
diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp
index 79fa0dd..ef1ca7f 100644
--- a/netfs/fuse/fuseApp.cpp
+++ b/netfs/fuse/fuseApp.cpp
@@ -1,5 +1,5 @@
#include <Glacier2/Router.h>
-#include <string.h>
+#include <cstring>
#include "fuseApp.h"
#include "lockHelpers.h"
#include "cache.impl.h"
@@ -14,8 +14,8 @@ namespace AdHoc {
template class CallCacheable<struct stat, std::string>;
}
-NetFS::FuseApp::FuseApp(const Ice::StringSeq & a) :
- iceArgs(a),
+NetFS::FuseApp::FuseApp(Ice::StringSeq a) :
+ iceArgs(std::move(a)),
sessionOpened(false),
openHandleId(0),
converter(userLookup, groupLookup)
@@ -77,7 +77,7 @@ NetFS::FuseApp::init(struct fuse_conn_info *)
{
ic = Ice::initialize(iceArgs);
fcr = configurator();
- return NULL;
+ return nullptr;
}
NetFS::Client::ResourcePtr
@@ -204,7 +204,7 @@ NetFS::FuseApp::verifyConnection()
session->ice_ping();
}
catch (const Ice::Exception &) {
- session = NULL;
+ session = nullptr;
sessionOpened = false;
}
}
@@ -213,7 +213,7 @@ NetFS::FuseApp::verifyConnection()
service->ice_ping();
}
catch (const Ice::Exception &) {
- service = NULL;
+ service = nullptr;
}
}
if (volume) {
@@ -221,13 +221,13 @@ NetFS::FuseApp::verifyConnection()
volume->ice_ping();
}
catch (const Ice::Exception &) {
- volume = NULL;
+ volume = nullptr;
}
}
}
int
-NetFS::FuseApp::onError(const std::exception & e) throw()
+NetFS::FuseApp::onError(const std::exception & e) noexcept
{
if (dynamic_cast<const Ice::SocketException *>(&e) || dynamic_cast<const Ice::TimeoutException *>(&e)) {
log(LOG_ERR, e.what());
@@ -245,7 +245,7 @@ NetFS::FuseApp::onError(const std::exception & e) throw()
}
if (dynamic_cast<const Ice::RequestFailedException *>(&e)) {
try {
- volume = NULL;
+ volume = nullptr;
connectToVolume();
connectHandles();
return 0;
diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h
index 23738b3..df342b6 100644
--- a/netfs/fuse/fuseApp.h
+++ b/netfs/fuse/fuseApp.h
@@ -20,7 +20,7 @@ namespace NetFS {
private:
class OpenDir {
public:
- OpenDir(DirectoryPrxPtr remote, const std::string & path);
+ OpenDir(DirectoryPrxPtr remote, std::string path);
DirectoryPrxPtr remote;
DirectoryV2PrxPtr remoteV2;
@@ -31,7 +31,7 @@ namespace NetFS {
class OpenFile {
public:
- OpenFile(FilePrxPtr remote, const std::string & path, int flags);
+ OpenFile(FilePrxPtr remote, std::string path, int flags);
void flush();
void wait() const;
@@ -49,7 +49,7 @@ namespace NetFS {
typedef std::map<int, OpenFilePtr> OpenFiles;
public:
- FuseApp(const Ice::StringSeq &);
+ FuseApp(Ice::StringSeq);
~FuseApp();
private:
diff --git a/netfs/fuse/fuseAppBase.cpp b/netfs/fuse/fuseAppBase.cpp
index 3eadd8f..4485aec 100644
--- a/netfs/fuse/fuseAppBase.cpp
+++ b/netfs/fuse/fuseAppBase.cpp
@@ -1,19 +1,13 @@
#include "fuseAppBase.h"
-#include <errno.h>
-#include <assert.h>
-#include <stdio.h>
+#include <cerrno>
+#include <cassert>
+#include <cstdio>
#include <unistd.h>
-#include <stdlib.h>
+#include <cstdlib>
#include <typeinfo>
FuseAppBase * FuseAppBase::fuseApp;
-FuseAppBase::FuseAppBase()
-{
-}
-FuseAppBase::~FuseAppBase()
-{
-}
// LCOV_EXCL_START
// These are all excluded from coverage because it is impossible
// to call them in a realistic manner. They exist only as the default
@@ -21,7 +15,7 @@ FuseAppBase::~FuseAppBase()
// unless it is overridden.
void * FuseAppBase::init(fuse_conn_info*)
{
- return NULL;
+ return nullptr;
}
int FuseAppBase::opt_parse(void*, const char *, int, fuse_args*)
{
@@ -155,6 +149,7 @@ int FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock *
{
return -ENOSYS;
}
+// NOLINTNEXTLINE(modernize-avoid-c-arrays)
int FuseAppBase::utimens(const char *, const struct timespec[2])
{
return -ENOSYS;
@@ -188,11 +183,11 @@ int FuseAppBase::fallocate(const char *, int, off_t, off_t, struct fuse_file_inf
return -ENOSYS;
}
// LCOV_EXCL_STOP
-void FuseAppBase::log(int level, const char * message) const throw()
+void FuseAppBase::log(int level, const char * message) const noexcept
{
logf(level, "%s", message);
}
-void FuseAppBase::logf(int level, const char * fmt, ...) const throw()
+void FuseAppBase::logf(int level, const char * fmt, ...) const noexcept
{
va_list args;
va_start(args, fmt);
@@ -200,7 +195,7 @@ void FuseAppBase::logf(int level, const char * fmt, ...) const throw()
va_end(args);
}
-int FuseAppBase::onError(const std::exception & e) throw()
+int FuseAppBase::onError(const std::exception & e) noexcept
{
logf(LOG_ERR, "Unknown exception (what: %s)", e.what());
return -ENOSYS;
@@ -222,12 +217,10 @@ void FuseAppBase::fuseDestroy(void *)
struct fuse_args
FuseAppBase::runint(int argc, char ** argv)
{
- struct fuse_opt fuse_opts[] = {
- { NULL, 0, 0 }
- };
+ std::array<fuse_opt, 1> fuse_opts {};
fuseApp = this;
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
- if (fuse_opt_parse(&args, fuseApp, fuse_opts,
+ if (fuse_opt_parse(&args, fuseApp, fuse_opts.data(),
&internalHelper<decltype(&FuseAppBase::opt_parse), &FuseAppBase::opt_parse>) == -1) {
exit(1);
}
diff --git a/netfs/fuse/fuseAppBase.h b/netfs/fuse/fuseAppBase.h
index f0866bb..2775c00 100644
--- a/netfs/fuse/fuseAppBase.h
+++ b/netfs/fuse/fuseAppBase.h
@@ -15,8 +15,7 @@
class DLL_PUBLIC FuseAppBase {
public:
- FuseAppBase();
- virtual ~FuseAppBase() = 0;
+ virtual ~FuseAppBase() = default;
virtual void * init (struct fuse_conn_info * info);
virtual int opt_parse(void *, const char * arg, int key, struct fuse_args *);
virtual int access(const char *, int);
diff --git a/netfs/fuse/fuseDirs.cpp b/netfs/fuse/fuseDirs.cpp
index 3d77101..58dab8e 100644
--- a/netfs/fuse/fuseDirs.cpp
+++ b/netfs/fuse/fuseDirs.cpp
@@ -3,10 +3,10 @@
#include <entCache.h>
namespace NetFS {
-FuseApp::OpenDir::OpenDir(DirectoryPrxPtr r, const std::string & p) :
- remote(r),
- remoteV2(r->ice_getFacet() >= "v02" ? Ice::uncheckedCast<DirectoryV2Prx>(r) : nullptr),
- path(p)
+FuseApp::OpenDir::OpenDir(DirectoryPrxPtr r, std::string p) :
+ remote(std::move(r)),
+ remoteV2(remote->ice_getFacet() >= "v02" ? Ice::uncheckedCast<DirectoryV2Prx>(r) : nullptr),
+ path(std::move(p))
{
}
@@ -52,16 +52,16 @@ FuseApp::readdir(const char * p, void * buf, fuse_fill_dir_t filler, off_t, stru
auto od = getProxy<OpenDirPtr>(fi->fh);
std::string path(p);
path += "/";
- auto expiry = time(NULL) + 2;
+ auto expiry = time(nullptr) + 2;
if (fcr->ListDir && od->remoteV2) {
for (const auto & e : od->remoteV2->listdir()) {
- filler(buf, e.first.c_str(), NULL, 0);
+ filler(buf, e.first.c_str(), nullptr, 0);
statCache.add(path + e.first, converter.convert(e.second), expiry);
}
}
else {
for (const auto & e : od->remote->readdir()) {
- filler(buf, e.c_str(), NULL, 0);
+ filler(buf, e.c_str(), nullptr, 0);
}
}
return 0;
diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp
index bbb7548..4ea7f47 100644
--- a/netfs/fuse/fuseFiles.cpp
+++ b/netfs/fuse/fuseFiles.cpp
@@ -1,4 +1,4 @@
-#include <string.h>
+#include <cstring>
#include "fuseApp.impl.h"
#include "fuseFiles.h"
#include "lockHelpers.h"
@@ -11,9 +11,9 @@ FuseApp::OpenFile::WriteState::WriteState() :
{
}
-FuseApp::OpenFile::OpenFile(FilePrxPtr r, const std::string & p, int f) :
- remote(r),
- path(p),
+FuseApp::OpenFile::OpenFile(FilePrxPtr r, std::string p, int f) :
+ remote(std::move(r)),
+ path(std::move(p)),
flags(f)
{
}
diff --git a/netfs/fuse/fuseMisc.cpp b/netfs/fuse/fuseMisc.cpp
index 5ece9a1..3d72f5c 100644
--- a/netfs/fuse/fuseMisc.cpp
+++ b/netfs/fuse/fuseMisc.cpp
@@ -1,5 +1,5 @@
#include "fuseApp.h"
-#include <string.h>
+#include <cstring>
#include <entCache.h>
int
@@ -113,6 +113,7 @@ NetFS::FuseApp::rename(const char * p1, const char * p2)
}
int
+// NOLINTNEXTLINE(modernize-avoid-c-arrays)
NetFS::FuseApp::utimens(const char * path, const struct timespec times[2])
{
try {
diff --git a/netfs/fuse/netfs.cpp b/netfs/fuse/netfs.cpp
index 2039eed..731327f 100644
--- a/netfs/fuse/netfs.cpp
+++ b/netfs/fuse/netfs.cpp
@@ -9,7 +9,7 @@ class FuseImpl : public NetFS::FuseApp {
openlog("netfs", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER);
}
- ~FuseImpl()
+ ~FuseImpl() override
{
closelog();
}
@@ -19,6 +19,7 @@ class FuseImpl : public NetFS::FuseApp {
return ::fuse_get_context();
}
+ // NOLINTNEXTLINE(modernize-avoid-c-arrays)
int fuse_opt_parse(struct fuse_args * args, void * data, const struct fuse_opt opts[], fuse_opt_proc_t proc) override
{
return ::fuse_opt_parse(args, data, opts, proc);
@@ -29,7 +30,7 @@ class FuseImpl : public NetFS::FuseApp {
return ::fuse_main(argc, argv, ops, this);
}
- void vlogf(int priority, const char * fmt, va_list args) const throw() override
+ void vlogf(int priority, const char * fmt, va_list args) const noexcept override
{
vsyslog(priority, fmt, args);
}
diff --git a/netfs/ice/entryResolver.h b/netfs/ice/entryResolver.h
index 1a20ec3..b5efbc3 100644
--- a/netfs/ice/entryResolver.h
+++ b/netfs/ice/entryResolver.h
@@ -7,7 +7,10 @@
template <class entry_t>
class EntryResolver {
public:
- typedef std::string name_t;
+ virtual ~EntryResolver() = default;
+
+ using name_t = std::string;
+
virtual void getID(const name_t &, id_t *) const = 0;
virtual void getName(const id_t &, name_t *) const = 0;
};
diff --git a/netfs/ice/typeConverter.cpp b/netfs/ice/typeConverter.cpp
index 46e8ff1..373877c 100644
--- a/netfs/ice/typeConverter.cpp
+++ b/netfs/ice/typeConverter.cpp
@@ -1,4 +1,5 @@
#include "typeConverter.h"
+#include <boost/numeric/conversion/cast.hpp>
EntryTypeConverter::EntryTypeConverter(const EntryResolver<uid_t> & u, const EntryResolver<gid_t> & g) :
userLookup(u),
@@ -6,6 +7,15 @@ EntryTypeConverter::EntryTypeConverter(const EntryResolver<uid_t> & u, const Ent
{
}
+// Wrapper function to assure no unexpected corruption occurs
+// during narrowing assignments.
+// (bugprone-narrowing-conversions)
+template<typename T, typename S>
+inline void safeAssign(T & t, const S & s)
+{
+ t = boost::numeric_cast<T>(s);
+}
+
struct stat
EntryTypeConverter::convert(const NetFS::Attr & a) const
{
@@ -74,17 +84,17 @@ NetFS::VFS
TypeConverter::convert(const struct statvfs & s) const
{
NetFS::VFS t;
- t.blockSize = s.f_bsize;
- t.fragmentSize = s.f_frsize;
+ safeAssign(t.blockSize, s.f_bsize);
+ safeAssign(t.fragmentSize, s.f_frsize);
t.blocks = s.f_blocks;
t.freeBlocks = s.f_bfree;
t.availBlocks = s.f_bavail;
t.files = s.f_files;
t.freeFiles = s.f_ffree;
t.availFiles = s.f_favail;
- t.FSID = s.f_fsid;
- t.flags = s.f_flag;
- t.maxNameLen = s.f_namemax;
+ safeAssign(t.FSID, s.f_fsid);
+ safeAssign(t.flags, s.f_flag);
+ safeAssign(t.maxNameLen, s.f_namemax);
return t;
}
diff --git a/netfs/lib/entCache.cpp b/netfs/lib/entCache.cpp
index fbdba3e..25e8902 100644
--- a/netfs/lib/entCache.cpp
+++ b/netfs/lib/entCache.cpp
@@ -5,16 +5,6 @@
#include <grp.h>
#include <visibility.h>
-template<class entry_t>
-EntCache<entry_t>::EntCache() :
- fillTime(0)
-{
-}
-
-template<class entry_t>
-EntCache<entry_t>::~EntCache()
-{
-}
template<class entry_t>
void
@@ -38,7 +28,7 @@ typename EntCache<entry_t>::entry_ptr
EntCache<entry_t>::getEntry(const key_t & key) const
{
typename EntCache<entry_t>::entry_ptr ent;
- if (fillTime + 60 > time(NULL)) {
+ if (fillTime + 60 > time(nullptr)) {
ent = getEntryNoFill<key_t>(key);
}
if (!ent) {
@@ -62,12 +52,12 @@ EntCache<entry_t>::getEntryNoFill(const key_t & key) const
if (i != collection.end()) {
return *i;
}
- return NULL;
+ return nullptr;
}
-User::User(uid_t u, const std::string & n, gid_t g) :
+User::User(uid_t u, std::string n, gid_t g) :
id(u),
- name(n),
+ name(std::move(n)),
group(g)
{
}
@@ -81,18 +71,18 @@ EntCache<User>::fillCache() const
Lock(lock);
setpwent();
idcache.clear();
- char buf[BUFLEN];
+ std::array<char, BUFLEN> buf;
struct passwd pwbuf, * pwp;
- while (getpwent_r(&pwbuf, buf, BUFLEN, &pwp) == 0) {
+ while (getpwent_r(&pwbuf, buf.data(), buf.size(), &pwp) == 0) {
idcache.insert(std::make_shared<User>(pwp->pw_uid, pwp->pw_name, pwp->pw_gid));
}
endpwent();
time(&fillTime);
}
-Group::Group(gid_t g, const std::string & n) :
+Group::Group(gid_t g, std::string n) :
id(g),
- name(n)
+ name(std::move(n))
{
}
@@ -102,11 +92,11 @@ EntCache<Group>::fillCache() const
{
Lock(lock);
setgrent();
- char buf[BUFLEN];
+ std::array<char, BUFLEN> buf;
idcache.clear();
struct group grpbuf, * grp;
EntCache<User> instance;
- while (getgrent_r(&grpbuf, buf, BUFLEN, &grp) == 0) {
+ while (getgrent_r(&grpbuf, buf.data(), buf.size(), &grp) == 0) {
auto g = std::make_shared<Group>(grp->gr_gid, grp->gr_name);
for (auto member = grp->gr_mem; *member; member++) {
try {
@@ -127,15 +117,11 @@ DLL_PUBLIC Group::hasMember(uid_t u) const
return (members.find(u) != members.end());
}
-template DLL_PUBLIC EntCache<User>::EntCache();
-template DLL_PUBLIC EntCache<User>::~EntCache();
template std::shared_ptr<User> DLL_PUBLIC EntCache<User>::getEntry<std::string>(const std::string &) const;
template std::shared_ptr<User> DLL_PUBLIC EntCache<User>::getEntry<uid_t>(const uid_t &) const;
template DLL_PUBLIC void EntCache<User>::getName(const gid_t &, std::string *) const;
template DLL_PUBLIC void EntCache<User>::getID(const std::string &, gid_t *) const;
-template DLL_PUBLIC EntCache<Group>::EntCache();
-template DLL_PUBLIC EntCache<Group>::~EntCache();
template std::shared_ptr<Group> DLL_PUBLIC EntCache<Group>::getEntry<std::string>(const std::string &) const;
template std::shared_ptr<Group> DLL_PUBLIC EntCache<Group>::getEntry<gid_t>(const gid_t &) const;
template DLL_PUBLIC void EntCache<Group>::getName(const gid_t &, std::string *) const;
diff --git a/netfs/lib/entCache.h b/netfs/lib/entCache.h
index 4c34a32..2833141 100644
--- a/netfs/lib/entCache.h
+++ b/netfs/lib/entCache.h
@@ -11,7 +11,7 @@
class User {
public:
- User(uid_t, const std::string &, gid_t);
+ User(uid_t, std::string, gid_t);
uid_t id;
std::string name;
gid_t group;
@@ -19,7 +19,7 @@ class User {
class Group {
public:
- Group(gid_t, const std::string &);
+ Group(gid_t, std::string);
bool hasMember(uid_t) const;
@@ -31,12 +31,9 @@ class Group {
template<class entry_t>
class EntCache : public EntryResolver<decltype(entry_t::id)> {
public:
- typedef decltype(entry_t::id) id_t;
- typedef decltype(entry_t::name) name_t;
- typedef std::shared_ptr<entry_t> entry_ptr;
-
- EntCache();
- virtual ~EntCache();
+ using id_t = decltype(entry_t::id);
+ using name_t = decltype(entry_t::name);
+ using entry_ptr = std::shared_ptr<entry_t>;
void getID(const name_t &, id_t *) const override;
void getName(const id_t &, name_t *) const override;
@@ -48,20 +45,20 @@ class EntCache : public EntryResolver<decltype(entry_t::id)> {
template<class key_t>
entry_ptr getEntryNoFill(const key_t &) const;
- typedef boost::multi_index::multi_index_container<std::shared_ptr<entry_t>,
+ using IDs = boost::multi_index::multi_index_container<std::shared_ptr<entry_t>,
boost::multi_index::indexed_by<
boost::multi_index::ordered_unique<
boost::multi_index::tag<id_t>, BOOST_MULTI_INDEX_MEMBER(entry_t, const id_t, id), std::less<>>,
boost::multi_index::ordered_unique<
boost::multi_index::tag<std::string>, BOOST_MULTI_INDEX_MEMBER(entry_t, const std::string, name), std::less<>>
- > > IDs;
+ > >;
mutable IDs idcache;
mutable std::shared_mutex lock;
- mutable time_t fillTime;
+ mutable time_t fillTime {0};
};
-typedef EntCache<User> UserEntCache;
-typedef EntCache<Group> GroupEntCache;
+using UserEntCache = EntCache<User>;
+using GroupEntCache = EntCache<Group>;
#endif
diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam
index a5dfbdf..3f82c04 100644
--- a/netfs/unittests/Jamfile.jam
+++ b/netfs/unittests/Jamfile.jam
@@ -2,6 +2,11 @@ import testing ;
lib boost_utf : : <name>boost_unit_test_framework ;
+project
+ : requirements
+ <toolset>tidy:<xcheckxx>misc-non-private-member-variables-in-classes
+ ;
+
path-constant me : . ;
lib testMocks :
diff --git a/netfs/unittests/mockDaemon.cpp b/netfs/unittests/mockDaemon.cpp
index 14b843f..50a313a 100644
--- a/netfs/unittests/mockDaemon.cpp
+++ b/netfs/unittests/mockDaemon.cpp
@@ -5,9 +5,9 @@
const std::filesystem::path TestExportRoot(binDir /
UniqueExport::get(getpid()));
-MockDaemon::MockDaemon(const std::string & ep) :
+MockDaemon::MockDaemon(std::string ep) :
NetFSDaemon(),
- testEndpoint(ep)
+ testEndpoint(std::move(ep))
{
}
@@ -22,9 +22,9 @@ MockDaemon::ReadConfiguration(const std::filesystem::path & path) const
return c;
}
-MockDaemonHost::MockDaemonHost(const std::string & ep, const Ice::StringSeq & ps) :
- testEndpoint(ep),
- params(ps),
+MockDaemonHost::MockDaemonHost(std::string ep, Ice::StringSeq ps) :
+ testEndpoint(std::move(ep)),
+ params(std::move(ps)),
daemon(nullptr)
{
std::filesystem::remove_all(TestExportRoot);
diff --git a/netfs/unittests/mockDaemon.h b/netfs/unittests/mockDaemon.h
index dd0a0ad..074d53f 100644
--- a/netfs/unittests/mockDaemon.h
+++ b/netfs/unittests/mockDaemon.h
@@ -9,7 +9,7 @@ AdHocFormatter(UniqueExport, "testExport-%?");
class DLL_PUBLIC MockDaemon : public NetFSDaemon {
public:
- MockDaemon(const std::string & ep);
+ MockDaemon(std::string ep);
const std::string testEndpoint;
@@ -19,7 +19,7 @@ class DLL_PUBLIC MockDaemon : public NetFSDaemon {
class DLL_PUBLIC MockDaemonHost {
public:
- MockDaemonHost(const std::string & ep, const Ice::StringSeq & ps = {});
+ MockDaemonHost(std::string ep, Ice::StringSeq ps = {});
~MockDaemonHost();
void restart();
diff --git a/netfs/unittests/mockFuse.cpp b/netfs/unittests/mockFuse.cpp
index d7b66a6..9e9ac87 100644
--- a/netfs/unittests/mockFuse.cpp
+++ b/netfs/unittests/mockFuse.cpp
@@ -1,9 +1,9 @@
#include "mockFuse.h"
#include <boost/test/test_tools.hpp>
-FuseMock::FuseMock(const std::string & ep, const Ice::StringSeq & a) :
- NetFS::FuseApp(a),
- testEndpoint(ep)
+FuseMock::FuseMock(std::string ep, Ice::StringSeq a) :
+ NetFS::FuseApp(std::move(a)),
+ testEndpoint(std::move(ep))
{
::memset(&context, 0, sizeof(fuse_context));
context.pid = getpid();
@@ -18,6 +18,7 @@ FuseMock::fuse_get_context()
}
int
+// NOLINTNEXTLINE(modernize-avoid-c-arrays)
FuseMock::fuse_opt_parse(struct fuse_args * args, void * data, const struct fuse_opt [], fuse_opt_proc_t proc)
{
for (int n = 0; n < args->argc; n += 1) {
@@ -29,7 +30,7 @@ FuseMock::fuse_opt_parse(struct fuse_args * args, void * data, const struct fuse
int
FuseMock::main(int, char **, const struct fuse_operations * o)
{
- o->init(NULL);
+ o->init(nullptr);
ops = *o;
return 0;
}
@@ -47,24 +48,19 @@ FuseMock::ReadConfiguration(const std::filesystem::path & path) const
}
void
-FuseMock::vlogf(int, const char * fmt, va_list args) const throw()
+FuseMock::vlogf(int, const char * fmt, va_list args) const noexcept
{
BOOST_TEST_MESSAGE(vstringf(fmt, args));
}
-FuseMockHost::FuseMockHost(const std::string & ep, const Ice::StringSeq & a) :
- app(new FuseMock(ep, a)),
+FuseMockHost::FuseMockHost(std::string ep, const Ice::StringSeq & a) :
+ app(std::make_unique<FuseMock>(std::move(ep), a)),
fuse(&app->ops)
{
std::vector<char *> argv;
for (auto & arg : a) {
argv.push_back(const_cast<char *>(arg.c_str()));
}
- FuseAppBase::run(a.size(), &argv.front(), app);
-}
-
-FuseMockHost::~FuseMockHost()
-{
- delete app;
+ FuseAppBase::run(a.size(), &argv.front(), app.get());
}
diff --git a/netfs/unittests/mockFuse.h b/netfs/unittests/mockFuse.h
index 9b3d2e0..7e4f3ad 100644
--- a/netfs/unittests/mockFuse.h
+++ b/netfs/unittests/mockFuse.h
@@ -6,7 +6,7 @@
class DLL_PUBLIC FuseMock : public NetFS::FuseApp {
public:
- FuseMock(const std::string &, const Ice::StringSeq &);
+ FuseMock(std::string, Ice::StringSeq);
struct fuse_context * fuse_get_context() override;
int fuse_opt_parse(struct fuse_args * args, void * data, const struct fuse_opt [], fuse_opt_proc_t proc) override;
@@ -25,11 +25,10 @@ class DLL_PUBLIC FuseMock : public NetFS::FuseApp {
class DLL_PUBLIC FuseMockHost {
public:
- FuseMockHost(const std::string &, const Ice::StringSeq &);
- ~FuseMockHost();
+ FuseMockHost(std::string, const Ice::StringSeq &);
private:
- FuseMock * app;
+ std::unique_ptr<FuseMock> app;
public:
const fuse_operations * fuse;
diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp
index 06ab752..07b5ce6 100644
--- a/netfs/unittests/testCore.cpp
+++ b/netfs/unittests/testCore.cpp
@@ -8,6 +8,7 @@
#include <ostream>
#include <algorithm>
#include <fuseFiles.h>
+#include <climits>
const auto testExport = UniqueExport::get(getpid());
const std::string testEndpoint("tcp -h localhost -p 12012");
@@ -22,8 +23,21 @@ operator==(const struct stat & a, const struct stat & b)
}
namespace std {
+ template<size_t l>
+ bool operator==(const std::array<char, l> & a, const char * b)
+ {
+ return strncmp(a.data(), b, l) == 0;
+ }
+
AdHocFormatter(StatDebug, "dev: %? inode: %?");
// LCOV_EXCL_START
+ template<typename T, size_t l>
+ ostream & operator<<(ostream & s, const std::array<T, l> & a)
+ {
+ std::copy(a.begin(), a.end(), std::ostream_iterator<T>(s));
+ return s;
+ }
+
ostream & operator<<(ostream & s, const struct stat & ss)
{
return StatDebug::write(s, ss.st_dev, ss.st_ino);
@@ -108,12 +122,8 @@ BOOST_AUTO_TEST_CASE ( clientInitialised )
BOOST_AUTO_TEST_CASE( testNavigation )
{
- struct stat attr, rootattr, insideattr;
- memset(&attr, 0, sizeof(attr));
- memset(&rootattr, 0, sizeof(rootattr));
- memset(&insideattr, 0, sizeof(insideattr));
- struct fuse_file_info fi;
- memset(&fi, 0, sizeof(fi));
+ struct stat attr {}, rootattr {}, insideattr {};
+ struct fuse_file_info fi {};
int fd = fuse->create("/inside", 0666, &fi);
BOOST_REQUIRE(fd >= 0);
fuse->release("/inside", &fi);
@@ -148,8 +158,7 @@ BOOST_AUTO_TEST_CASE( testSandboxing )
std::filesystem::remove(binDir / "outside");
std::filesystem::remove(binDir / "sub" / "outside");
std::filesystem::remove(binDir / "sub");
- struct fuse_file_info fi;
- memset(&fi, 0, sizeof(fi));
+ struct fuse_file_info fi {};
BOOST_REQUIRE_EQUAL(fuse->create("../outside", 0666, &fi), -EPERM);
BOOST_REQUIRE(!std::filesystem::exists(binDir / "outside"));
BOOST_REQUIRE_EQUAL(fuse->create("/../outside", 0666, &fi), -EPERM);
@@ -173,8 +182,7 @@ BOOST_AUTO_TEST_CASE( testSandboxing )
void
enableWriteOnDir(const fuse_operations * fuse, const char * dir)
{
- struct stat st;
- memset(&st, 0, sizeof(st));
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->chmod(dir, 0700), 0);
BOOST_REQUIRE_EQUAL(fuse->getattr(dir, &st), 0);
BOOST_REQUIRE_EQUAL(st.st_mode, 0700 | S_IFDIR);
@@ -183,8 +191,7 @@ enableWriteOnDir(const fuse_operations * fuse, const char * dir)
void
disableWriteOnDir(const fuse_operations * fuse, const char * dir)
{
- struct stat st;
- memset(&st, 0, sizeof(st));
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->chmod(dir, 0500), 0);
BOOST_REQUIRE_EQUAL(fuse->getattr(dir, &st), 0);
BOOST_REQUIRE_EQUAL(st.st_mode, 0500 | S_IFDIR);
@@ -192,10 +199,8 @@ disableWriteOnDir(const fuse_operations * fuse, const char * dir)
BOOST_AUTO_TEST_CASE( directories )
{
- struct fuse_file_info fi;
- memset(&fi, 0, sizeof(fi));
- struct stat st;
- memset(&st, 0, sizeof(st));
+ struct fuse_file_info fi {};
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->mkdir("/test", 0700), 0);
BOOST_REQUIRE(std::filesystem::is_directory(binDir / testExport / "test"));
BOOST_REQUIRE_EQUAL(fuse->mkdir("/test", 0700), -EEXIST);
@@ -238,11 +243,8 @@ BOOST_AUTO_TEST_CASE( directories )
BOOST_AUTO_TEST_CASE( files )
{
- struct fuse_file_info fi;
- memset(&fi, 0, sizeof(fi));
- struct stat st, st2;
- memset(&st, 0, sizeof(st));
- memset(&st2, 0, sizeof(st2));
+ struct fuse_file_info fi {};
+ struct stat st {}, st2 {};
fi.flags = O_RDWR;
BOOST_REQUIRE_EQUAL(fuse->open("/test", &fi), -ENOENT);
BOOST_REQUIRE_EQUAL(fuse->create("/test", 0600, &fi), 0);
@@ -266,21 +268,20 @@ BOOST_AUTO_TEST_CASE( files )
BOOST_REQUIRE_EQUAL(fuse->write("/test2", "BUFFER some", 11, 10, &fi), 11);
BOOST_REQUIRE_EQUAL(fuse->fgetattr("/test2", &st2, &fi), 0);
BOOST_REQUIRE_EQUAL(st2.st_size, 21);
- char buf[11];
- memset(&buf, 0, sizeof(buf));
- BOOST_REQUIRE_EQUAL(fuse->read("/test2", buf, 10, 5, &fi), 10);
+ 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->ftruncate("/test2", 11, &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->fgetattr("/test2", &st2, &fi), 0);
BOOST_REQUIRE_EQUAL(st2.st_size, 11);
- memset(&buf, 0, sizeof(buf));
- BOOST_REQUIRE_EQUAL(fuse->read("/test2", buf, 10, 5, &fi), 6);
+ buf = {};
+ BOOST_REQUIRE_EQUAL(fuse->read("/test2", buf.data(), 10, 5, &fi), 6);
BOOST_REQUIRE_EQUAL(buf, "test B");
BOOST_REQUIRE_EQUAL(fuse->truncate("/test2", 7), 0);
BOOST_REQUIRE_EQUAL(fuse->fgetattr("/test2", &st2, &fi), 0);
BOOST_REQUIRE_EQUAL(st2.st_size, 7);
- memset(&buf, 0, sizeof(buf));
- BOOST_REQUIRE_EQUAL(fuse->read("/test2", buf, 10, 5, &fi), 2);
+ buf = {};
+ BOOST_REQUIRE_EQUAL(fuse->read("/test2", buf.data(), 10, 5, &fi), 2);
BOOST_REQUIRE_EQUAL(buf, "te");
BOOST_REQUIRE_EQUAL(fuse->release("/test2", &fi), 0);
@@ -297,12 +298,10 @@ BOOST_AUTO_TEST_CASE( files )
BOOST_AUTO_TEST_CASE( bgwriteOverlapped, * boost::unit_test::timeout(2) )
{
- struct fuse_file_info fi;
- memset(&fi, 0, sizeof(fi));
- struct stat st;
- memset(&st, 0, sizeof(st));
+ struct fuse_file_info fi {};
+ struct stat st {};
fi.flags = O_RDWR;
- auto s = sizeof(int32_t);
+ constexpr auto s = sizeof(int32_t);
auto N = 20;
BOOST_REQUIRE_EQUAL(fuse->create("/test", 0600, &fi), 0);
for (int32_t n = 0; n < N; n += 1) {
@@ -310,9 +309,9 @@ BOOST_AUTO_TEST_CASE( bgwriteOverlapped, * boost::unit_test::timeout(2) )
}
BOOST_REQUIRE_EQUAL(fuse->fgetattr("/test", &st, &fi), 0);
BOOST_REQUIRE_EQUAL(st.st_size, N + s - 1);
- char buf[s];
- BOOST_REQUIRE_EQUAL(fuse->read("/test", buf, s, (N - 1), &fi), s);
- BOOST_REQUIRE_EQUAL(*(int*)buf, N - 1);
+ std::array<char, s> buf;
+ BOOST_REQUIRE_EQUAL(fuse->read("/test", buf.data(), s, (N - 1), &fi), s);
+ BOOST_REQUIRE_EQUAL(*(int*)buf.data(), N - 1);
BOOST_REQUIRE_EQUAL(fuse->release("/test", &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->getattr("/test", &st), 0);
BOOST_REQUIRE_EQUAL(st.st_size, N + s - 1);
@@ -320,12 +319,10 @@ BOOST_AUTO_TEST_CASE( bgwriteOverlapped, * boost::unit_test::timeout(2) )
BOOST_AUTO_TEST_CASE( bgwriteDistinct, * boost::unit_test::timeout(2) )
{
- struct fuse_file_info fi;
- memset(&fi, 0, sizeof(fi));
- struct stat st;
- memset(&st, 0, sizeof(st));
+ struct fuse_file_info fi {};
+ struct stat st {};
fi.flags = O_RDWR;
- auto s = sizeof(int32_t);
+ constexpr auto s = sizeof(int32_t);
auto N = 20;
BOOST_REQUIRE_EQUAL(fuse->create("/test", 0600, &fi), 0);
for (int32_t n = 0; n < N; n += 1) {
@@ -333,9 +330,9 @@ BOOST_AUTO_TEST_CASE( bgwriteDistinct, * boost::unit_test::timeout(2) )
}
BOOST_REQUIRE_EQUAL(fuse->fgetattr("/test", &st, &fi), 0);
BOOST_REQUIRE_EQUAL(st.st_size, N * s);
- char buf[s];
- BOOST_REQUIRE_EQUAL(fuse->read("/test", buf, s, (N - 1) * s, &fi), s);
- BOOST_REQUIRE_EQUAL(*(int*)buf, N - 1);
+ std::array<char, s> buf;
+ BOOST_REQUIRE_EQUAL(fuse->read("/test", buf.data(), s, (N - 1) * s, &fi), s);
+ BOOST_REQUIRE_EQUAL(*(int*)buf.data(), N - 1);
BOOST_REQUIRE_EQUAL(fuse->release("/test", &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->getattr("/test", &st), 0);
BOOST_REQUIRE_EQUAL(st.st_size, N * s);
@@ -343,12 +340,12 @@ BOOST_AUTO_TEST_CASE( bgwriteDistinct, * boost::unit_test::timeout(2) )
BOOST_AUTO_TEST_CASE( symlinks )
{
- char buf[BUFSIZ];
+ std::array<char, PATH_MAX> buf;
BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir", 0700), 0);
- BOOST_REQUIRE_EQUAL(fuse->readlink("/dir", buf, BUFSIZ), -EINVAL);
+ BOOST_REQUIRE_EQUAL(fuse->readlink("/dir", buf.data(), buf.size()), -EINVAL);
BOOST_REQUIRE_EQUAL(fuse->symlink("/test2", "/test3"), 0);
BOOST_REQUIRE_EQUAL(fuse->symlink("/test2", "/test3"), -EEXIST);
- BOOST_REQUIRE_EQUAL(fuse->readlink("/test3", buf, BUFSIZ), 0);
+ BOOST_REQUIRE_EQUAL(fuse->readlink("/test3", buf.data(), buf.size()), 0);
BOOST_REQUIRE_EQUAL("/test2", buf);
BOOST_REQUIRE_EQUAL(fuse->unlink("/test3"), 0);
BOOST_REQUIRE_EQUAL(fuse->unlink("/test3"), -ENOENT);
@@ -359,8 +356,7 @@ BOOST_AUTO_TEST_CASE( symlinks )
BOOST_AUTO_TEST_CASE( access )
{
- struct stat st;
- memset(&st, 0, sizeof(st));
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->access("/", F_OK), 0);
BOOST_REQUIRE_EQUAL(fuse->access("/missing", F_OK), -ENOENT);
// Basic assertions
@@ -386,8 +382,7 @@ BOOST_AUTO_TEST_CASE( access )
BOOST_AUTO_TEST_CASE( permissionsDirs )
{
- struct stat st;
- memset(&st, 0, sizeof(st));
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir", 0700), 0);
BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir/yes", 0000), 0);
BOOST_REQUIRE_EQUAL(fuse->getattr("/dir/yes", &st), 0);
@@ -403,10 +398,8 @@ BOOST_AUTO_TEST_CASE( permissionsDirs )
BOOST_AUTO_TEST_CASE( permissionsFiles )
{
- struct stat st;
- memset(&st, 0, sizeof(st));
- struct fuse_file_info fi;
- memset(&fi, 0, sizeof(fi));
+ struct stat st {};
+ struct fuse_file_info fi {};
fi.flags = O_RDWR;
BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir", 0700), 0);
BOOST_REQUIRE_NE(fuse->create("/dir/yes", 0000, &fi), -1);
@@ -426,8 +419,7 @@ BOOST_AUTO_TEST_CASE( mknod )
{
BOOST_REQUIRE_EQUAL(fuse->mknod("/nod", 0600 | S_IFIFO, 0), 0);
BOOST_REQUIRE_EQUAL(fuse->mknod("/nod", 0600 | S_IFIFO, 0), -EEXIST);
- struct stat st;
- memset(&st, 0, sizeof(st));
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->getattr("/nod", &st), 0);
BOOST_REQUIRE_EQUAL(st.st_mode, 0600 | S_IFIFO);
BOOST_REQUIRE_EQUAL(fuse->unlink("/nod"), 0);
@@ -439,8 +431,7 @@ BOOST_AUTO_TEST_CASE( mknod )
BOOST_AUTO_TEST_CASE( renameToDir )
{
- struct fuse_file_info fi;
- memset(&fi, 0, sizeof(fi));
+ struct fuse_file_info fi {};
BOOST_REQUIRE_EQUAL(fuse->create("/file", 0600, &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->release("/file", &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir", 0700), 0);
@@ -461,8 +452,7 @@ BOOST_AUTO_TEST_CASE( chown )
{
BOOST_REQUIRE_EQUAL(fuse->mkdir("/dir", 0777), 0);
BOOST_REQUIRE_EQUAL(fuse->chown("/dir", getuid(), getgid()), 0);
- struct stat st;
- memset(&st, 0, sizeof(st));
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->getattr("/dir", &st), 0);
BOOST_REQUIRE_EQUAL(st.st_uid, getuid());
BOOST_REQUIRE_EQUAL(st.st_gid, getgid());
@@ -473,16 +463,11 @@ BOOST_AUTO_TEST_CASE( chown )
BOOST_AUTO_TEST_CASE( utimens )
{
BOOST_REQUIRE_EQUAL(fuse->mknod("/file", 0600, 0), 0);
- struct timespec times[2];
- times[0].tv_sec = 1;
- times[0].tv_nsec = 100;
- times[1].tv_sec = 2;
- times[1].tv_nsec = 200;
- BOOST_REQUIRE_EQUAL(fuse->utimens("/file", times), 0);
+ std::array<timespec, 2> times { { {1, 100}, { 2, 200 } } };
+ BOOST_REQUIRE_EQUAL(fuse->utimens("/file", times.data()), 0);
times[1].tv_nsec = -200;
- BOOST_REQUIRE_EQUAL(fuse->utimens("/file", times), -EINVAL);
- struct stat st;
- memset(&st, 0, sizeof(st));
+ BOOST_REQUIRE_EQUAL(fuse->utimens("/file", times.data()), -EINVAL);
+ struct stat st {};
BOOST_REQUIRE_EQUAL(fuse->getattr("/file", &st), 0);
BOOST_REQUIRE_EQUAL(st.st_atime, 1);
BOOST_REQUIRE_EQUAL(st.st_atim.tv_sec, 1);
@@ -508,8 +493,7 @@ BOOST_FIXTURE_TEST_SUITE( NetfsAltCore, AltCore );
BOOST_AUTO_TEST_CASE( noListDir )
{
- struct fuse_file_info fi;
- memset(&fi, 0, sizeof(fi));
+ struct fuse_file_info fi {};
BOOST_REQUIRE_EQUAL(fuse->mkdir("/test", 0700), 0);
BOOST_REQUIRE(std::filesystem::is_directory(binDir / testExport / "test"));
BOOST_REQUIRE_EQUAL(fuse->mkdir("/test", 0700), -EEXIST);
@@ -548,18 +532,15 @@ BOOST_AUTO_TEST_CASE( noListDir )
BOOST_AUTO_TEST_CASE( testFGWrites )
{
- struct fuse_file_info fi;
- memset(&fi, 0, sizeof(fi));
- struct stat st;
- memset(&st, 0, sizeof(st));
+ struct fuse_file_info fi {};
+ struct stat st {};
fi.flags = O_RDWR;
BOOST_REQUIRE_EQUAL(fuse->create("/test", 0600, &fi), 0);
BOOST_REQUIRE_EQUAL(fuse->write("/test", "some test buffer", 16, 0, &fi), 16);
BOOST_REQUIRE_EQUAL(fuse->getattr("/test", &st), 0);
BOOST_REQUIRE_EQUAL(st.st_size, 16);
- char buf[11];
- memset(&buf, 0, sizeof(buf));
- BOOST_REQUIRE_EQUAL(fuse->read("/test", buf, 10, 5, &fi), 10);
+ std::array<char, 11> buf {};
+ BOOST_REQUIRE_EQUAL(fuse->read("/test", buf.data(), 10, 5, &fi), 10);
BOOST_REQUIRE_EQUAL(buf, "test buffe");
BOOST_REQUIRE_EQUAL(fuse->release("/test", &fi), 0);
}
diff --git a/netfs/unittests/testEdgeCases.cpp b/netfs/unittests/testEdgeCases.cpp
index 0cfb888..1c6c3e6 100644
--- a/netfs/unittests/testEdgeCases.cpp
+++ b/netfs/unittests/testEdgeCases.cpp
@@ -35,11 +35,11 @@ BOOST_AUTO_TEST_CASE ( createAndDaemonRestart )
BOOST_REQUIRE_EQUAL(st.st_gid, getgid());
BOOST_TEST_CHECKPOINT("Write some data");
- char someData[890];
+ std::array<char, 890> someData;
for (auto & d : someData) {
d = rand();
}
- BOOST_REQUIRE_EQUAL(sizeof(someData), fuse.fuse->write(fileName, someData, sizeof(someData), 0, &fh));
+ BOOST_REQUIRE_EQUAL(sizeof(someData), fuse.fuse->write(fileName, someData.data(), someData.size(), 0, &fh));
BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh));
BOOST_REQUIRE_EQUAL(st.st_size, sizeof(someData));