From 46f6aa3507120f4b69a54abc02d8829eac005b6f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 1 Apr 2019 19:08:09 +0100 Subject: Enable hicpp tidy checks --- Jamroot.jam | 3 ++ netfs/daemon/daemonDirectory.cpp | 3 +- netfs/daemon/daemonFile.cpp | 2 +- netfs/daemon/daemonVolume.cpp | 44 +++++++++++++-------------- netfs/daemon/daemonVolume.h | 36 +++++++++++------------ netfs/daemon/modeCheck.cpp | 62 ++++++++++++++++++++++++++++++--------- netfs/fuse/fuseAppBase.cpp | 5 +++- netfs/fuse/fuseMisc.cpp | 2 +- netfs/fuse/netfs.cpp | 9 ++++-- netfs/ice/typeConverter.cpp | 8 ++--- netfs/lib/entCache.cpp | 8 ++--- netfs/unittests/Jamfile.jam | 3 ++ netfs/unittests/mockFuse.cpp | 6 ++-- netfs/unittests/testEdgeCases.cpp | 14 ++++----- netfs/unittests/testGlacier.cpp | 2 +- 15 files changed, 129 insertions(+), 78 deletions(-) diff --git a/Jamroot.jam b/Jamroot.jam index 8677573..a513dc4 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -21,6 +21,9 @@ project tidy:clang-* tidy:misc-* tidy:modernize-* + tidy:hicpp-* + tidy:hicpp-vararg + tidy:hicpp-signed-bitwise ; build-project netfs ; diff --git a/netfs/daemon/daemonDirectory.cpp b/netfs/daemon/daemonDirectory.cpp index 44aa765..5e5c8ad 100644 --- a/netfs/daemon/daemonDirectory.cpp +++ b/netfs/daemon/daemonDirectory.cpp @@ -53,7 +53,8 @@ DirectoryServer::listdir(const Ice::Current&) throw NetFS::SystemError(errno); // LCOV_EXCL_STOP } - struct stat s; + struct stat s {}; + // NOLINTNEXTLINE(hicpp-no-array-decay) if (::fstatat(fd, d->d_name, &s, AT_SYMLINK_NOFOLLOW) != 0) { // LCOV_EXCL_START throw NetFS::SystemError(errno); diff --git a/netfs/daemon/daemonFile.cpp b/netfs/daemon/daemonFile.cpp index 1113904..48730bc 100644 --- a/netfs/daemon/daemonFile.cpp +++ b/netfs/daemon/daemonFile.cpp @@ -27,7 +27,7 @@ NetFS::Attr FileServer::fgetattr(const NetFS::ReqEnv re, const Ice::Current &) { (void)re; - struct stat s; + struct stat s {}; if (::fstat(fd, &s) != 0) { throw NetFS::SystemError(errno); } diff --git a/netfs/daemon/daemonVolume.cpp b/netfs/daemon/daemonVolume.cpp index fd2f895..074580c 100644 --- a/netfs/daemon/daemonVolume.cpp +++ b/netfs/daemon/daemonVolume.cpp @@ -30,10 +30,10 @@ VolumeServer::disconnect(const Ice::Current & ice) } Ice::Int -VolumeServer::access(const NetFS::ReqEnv re, const std::string path, Ice::Int mode, const Ice::Current &) +VolumeServer::access(const NetFS::ReqEnv re, std::string path, Ice::Int mode, const Ice::Current &) { ModeCheck mc(re, root, userLookup, groupLookup); - struct stat s; + struct stat s {}; std::filesystem::path p(resolvePath(std::move(path))); if (::stat(p.c_str(), &s) != 0) { return errno; @@ -56,10 +56,10 @@ VolumeServer::access(const NetFS::ReqEnv re, const std::string path, Ice::Int mo } NetFS::Attr -VolumeServer::getattr(const NetFS::ReqEnv re, const std::string path, const Ice::Current &) +VolumeServer::getattr(const NetFS::ReqEnv re, std::string path, const Ice::Current &) { ModeCheck mc(re, root, userLookup, groupLookup); - struct stat s; + struct stat s {}; std::filesystem::path p(resolvePath(std::move(path))); mc.AssertReadParent(p); if (::lstat(p.c_str(), &s) != 0) { @@ -69,7 +69,7 @@ VolumeServer::getattr(const NetFS::ReqEnv re, const std::string path, const Ice: } void -VolumeServer::mknod(const NetFS::ReqEnv re, const std::string path, Ice::Int mode, Ice::Int dev, const Ice::Current&) +VolumeServer::mknod(const NetFS::ReqEnv re, std::string path, Ice::Int mode, Ice::Int dev, const Ice::Current&) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -81,7 +81,7 @@ VolumeServer::mknod(const NetFS::ReqEnv re, const std::string path, Ice::Int mod } void -VolumeServer::symlink(const NetFS::ReqEnv re, const std::string path1, const std::string path2, const Ice::Current &) +VolumeServer::symlink(const NetFS::ReqEnv re, const std::string path1, std::string path2, const Ice::Current &) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -97,7 +97,7 @@ VolumeServer::symlink(const NetFS::ReqEnv re, const std::string path1, const std } void -VolumeServer::link(const NetFS::ReqEnv re, const std::string path1, const std::string path2, const Ice::Current &) +VolumeServer::link(const NetFS::ReqEnv re, std::string path1, std::string path2, const Ice::Current &) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -113,7 +113,7 @@ VolumeServer::link(const NetFS::ReqEnv re, const std::string path1, const std::s } void -VolumeServer::rename(const NetFS::ReqEnv re, const std::string from, const std::string to, const Ice::Current &) +VolumeServer::rename(const NetFS::ReqEnv re, std::string from, std::string to, const Ice::Current &) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -127,7 +127,7 @@ VolumeServer::rename(const NetFS::ReqEnv re, const std::string from, const std:: } std::string -VolumeServer::readlink(const NetFS::ReqEnv re, const std::string path, const Ice::Current &) +VolumeServer::readlink(const NetFS::ReqEnv re, std::string path, const Ice::Current &) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -143,7 +143,7 @@ VolumeServer::readlink(const NetFS::ReqEnv re, const std::string path, const Ice } void -VolumeServer::chmod(const NetFS::ReqEnv re, const std::string path, Ice::Int mode, const Ice::Current &) +VolumeServer::chmod(const NetFS::ReqEnv re, std::string path, Ice::Int mode, const Ice::Current &) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -155,7 +155,7 @@ VolumeServer::chmod(const NetFS::ReqEnv re, const std::string path, Ice::Int mod } void -VolumeServer::chown(const NetFS::ReqEnv re, const std::string path, Ice::Int uid, Ice::Int gid, const Ice::Current &) +VolumeServer::chown(const NetFS::ReqEnv re, std::string path, Ice::Int uid, Ice::Int gid, const Ice::Current &) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -167,7 +167,7 @@ VolumeServer::chown(const NetFS::ReqEnv re, const std::string path, Ice::Int uid } void -VolumeServer::utimens(const NetFS::ReqEnv re, const std::string path, +VolumeServer::utimens(const NetFS::ReqEnv re, std::string path, Ice::Long s0, Ice::Long ns0, Ice::Long s1, Ice::Long ns1, const Ice::Current&) { ModeCheck mc(re, root, userLookup, groupLookup); @@ -181,11 +181,11 @@ VolumeServer::utimens(const NetFS::ReqEnv re, const std::string path, } NetFS::VFS -VolumeServer::statfs(const NetFS::ReqEnv re, const std::string path, const Ice::Current&) +VolumeServer::statfs(const NetFS::ReqEnv re, std::string path, const Ice::Current&) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; - struct statvfs s; + struct statvfs s {}; std::filesystem::path p(resolvePath(std::move(path))); mc.AssertRead(p); if (::statvfs(p.c_str(), &s) != 0) { @@ -195,7 +195,7 @@ VolumeServer::statfs(const NetFS::ReqEnv re, const std::string path, const Ice:: } void -VolumeServer::truncate(const NetFS::ReqEnv re, const std::string path, Ice::Long size, const Ice::Current&) +VolumeServer::truncate(const NetFS::ReqEnv re, std::string path, Ice::Long size, const Ice::Current&) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -207,7 +207,7 @@ VolumeServer::truncate(const NetFS::ReqEnv re, const std::string path, Ice::Long } void -VolumeServer::unlink(const NetFS::ReqEnv re, const std::string path, const Ice::Current&) +VolumeServer::unlink(const NetFS::ReqEnv re, std::string path, const Ice::Current&) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -219,7 +219,7 @@ VolumeServer::unlink(const NetFS::ReqEnv re, const std::string path, const Ice:: } NetFS::FilePrxPtr -VolumeServer::open(const NetFS::ReqEnv re, const std::string path, Ice::Int flags, const Ice::Current & ice) +VolumeServer::open(const NetFS::ReqEnv re, std::string path, Ice::Int flags, const Ice::Current & ice) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -237,7 +237,7 @@ VolumeServer::open(const NetFS::ReqEnv re, const std::string path, Ice::Int flag } NetFS::FilePrxPtr -VolumeServer::create(const NetFS::ReqEnv re, const std::string path, Ice::Int flags, Ice::Int mode, const Ice::Current & ice) +VolumeServer::create(const NetFS::ReqEnv re, std::string path, Ice::Int flags, Ice::Int mode, const Ice::Current & ice) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -257,7 +257,7 @@ VolumeServer::create(const NetFS::ReqEnv re, const std::string path, Ice::Int fl } NetFS::DirectoryPrxPtr -VolumeServer::opendir(const NetFS::ReqEnv re, const std::string path, const Ice::Current & ice) +VolumeServer::opendir(const NetFS::ReqEnv re, std::string path, const Ice::Current & ice) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -272,7 +272,7 @@ VolumeServer::opendir(const NetFS::ReqEnv re, const std::string path, const Ice: } void -VolumeServer::mkdir(const NetFS::ReqEnv re, const std::string path, Ice::Int mode, const Ice::Current&) +VolumeServer::mkdir(const NetFS::ReqEnv re, std::string path, Ice::Int mode, const Ice::Current&) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -288,7 +288,7 @@ VolumeServer::mkdir(const NetFS::ReqEnv re, const std::string path, Ice::Int mod } void -VolumeServer::rmdir(const NetFS::ReqEnv re, const std::string path, const Ice::Current&) +VolumeServer::rmdir(const NetFS::ReqEnv re, std::string path, const Ice::Current&) { ModeCheck mc(re, root, userLookup, groupLookup); errno = 0; @@ -323,7 +323,7 @@ normalizedAppend(std::filesystem::path out, const std::filesystem::path && in) } std::filesystem::path -VolumeServer::resolvePath(const std::string && path) const +VolumeServer::resolvePath(std::string path) const { return normalizedAppend(root, std::move(path)); } diff --git a/netfs/daemon/daemonVolume.h b/netfs/daemon/daemonVolume.h index 5087654..190f146 100644 --- a/netfs/daemon/daemonVolume.h +++ b/netfs/daemon/daemonVolume.h @@ -11,35 +11,35 @@ class VolumeServer : public NetFS::Volume { public: VolumeServer(const std::filesystem::path & root, const EntCache &, const EntCache &); - virtual NetFS::DirectoryPrxPtr opendir(const NetFS::ReqEnv, const std::string path, const Ice::Current&) override; + virtual NetFS::DirectoryPrxPtr opendir(const NetFS::ReqEnv, std::string path, const Ice::Current&) override; - virtual void mkdir(const NetFS::ReqEnv, const std::string path, Ice::Int id, const Ice::Current&) override; - virtual void rmdir(const NetFS::ReqEnv, const std::string path, const Ice::Current&) override; + virtual void mkdir(const NetFS::ReqEnv, std::string path, Ice::Int id, const Ice::Current&) override; + virtual void rmdir(const NetFS::ReqEnv, std::string path, const Ice::Current&) override; - virtual void truncate(const NetFS::ReqEnv, const std::string path, Ice::Long size, const Ice::Current&) override; + virtual void truncate(const NetFS::ReqEnv, std::string path, Ice::Long size, const Ice::Current&) override; - virtual void unlink(const NetFS::ReqEnv, const std::string path, const Ice::Current&) override; + virtual void unlink(const NetFS::ReqEnv, std::string path, const Ice::Current&) override; - virtual NetFS::FilePrxPtr open(const NetFS::ReqEnv, const std::string path, Ice::Int flags, const Ice::Current&) override; - virtual NetFS::FilePrxPtr create(const NetFS::ReqEnv, const std::string path, Ice::Int flags, Ice::Int mode, const Ice::Current&) override; + virtual NetFS::FilePrxPtr open(const NetFS::ReqEnv, std::string path, Ice::Int flags, const Ice::Current&) override; + virtual NetFS::FilePrxPtr create(const NetFS::ReqEnv, std::string path, Ice::Int flags, Ice::Int mode, const Ice::Current&) override; - virtual NetFS::VFS statfs(const NetFS::ReqEnv, const std::string path, const Ice::Current&) override; + virtual NetFS::VFS statfs(const NetFS::ReqEnv, std::string path, const Ice::Current&) override; - virtual Ice::Int access(const NetFS::ReqEnv, const std::string path, Ice::Int mode, const Ice::Current&) override; - virtual NetFS::Attr getattr(const NetFS::ReqEnv, const std::string path, const Ice::Current&) override; - virtual void mknod(const NetFS::ReqEnv, const std::string path, Ice::Int mode, Ice::Int dev, const Ice::Current&) override; + virtual Ice::Int access(const NetFS::ReqEnv, std::string path, Ice::Int mode, const Ice::Current&) override; + virtual NetFS::Attr getattr(const NetFS::ReqEnv, std::string path, const Ice::Current&) override; + virtual void mknod(const NetFS::ReqEnv, std::string path, Ice::Int mode, Ice::Int dev, const Ice::Current&) override; virtual void symlink(const NetFS::ReqEnv, const std::string path1, const std::string path2, const Ice::Current&) override; - virtual void link(const NetFS::ReqEnv, const std::string path1, const std::string path2, const Ice::Current&) override; - virtual void rename(const NetFS::ReqEnv, const std::string path1, const std::string path2, const Ice::Current&) override; - virtual std::string readlink(const NetFS::ReqEnv, const std::string path, const Ice::Current&) override; - virtual void chmod(const NetFS::ReqEnv, const std::string path, Ice::Int mode, const Ice::Current&) override; - virtual void chown(const NetFS::ReqEnv, const std::string path, Ice::Int uid, Ice::Int gid, const Ice::Current&) override; - virtual void utimens(const NetFS::ReqEnv, const std::string path, Ice::Long, Ice::Long, Ice::Long, Ice::Long, const Ice::Current&) override; + virtual void link(const NetFS::ReqEnv, std::string path1, std::string path2, const Ice::Current&) override; + virtual void rename(const NetFS::ReqEnv, std::string path1, const std::string path2, const Ice::Current&) override; + virtual std::string readlink(const NetFS::ReqEnv, std::string path, const Ice::Current&) override; + virtual void chmod(const NetFS::ReqEnv, std::string path, Ice::Int mode, const Ice::Current&) override; + virtual void chown(const NetFS::ReqEnv, std::string path, Ice::Int uid, Ice::Int gid, const Ice::Current&) override; + virtual void utimens(const NetFS::ReqEnv, std::string path, Ice::Long, Ice::Long, Ice::Long, Ice::Long, const Ice::Current&) override; virtual void disconnect(const Ice::Current&) override; protected: - std::filesystem::path resolvePath(const std::string && path) const; + std::filesystem::path resolvePath(std::string path) const; private: const std::filesystem::path root; diff --git a/netfs/daemon/modeCheck.cpp b/netfs/daemon/modeCheck.cpp index 91bbe20..58ade75 100644 --- a/netfs/daemon/modeCheck.cpp +++ b/netfs/daemon/modeCheck.cpp @@ -64,10 +64,10 @@ ModeCheck::AssertWritePerms(const std::filesystem::path & p) const } } -struct stat + struct stat ModeCheck::lstat(const std::filesystem::path & p) { - struct stat s; + struct stat s {}; if (::lstat(p.c_str(), &s) != 0) { throw NetFS::SystemError(errno); } @@ -77,30 +77,64 @@ ModeCheck::lstat(const std::filesystem::path & p) bool ModeCheck::ReadableBy(const struct stat & s, uid_t u, gid_t g) const { - if (u == 0) return true; - if (s.st_mode & S_IROTH) return true; - if (s.st_mode & S_IRUSR && s.st_uid == u) return true; - if (s.st_mode & S_IRGRP && (s.st_gid == g || userLookup.getEntry(u)->group == s.st_gid || groupLookup.getEntry(s.st_gid)->hasMember(u))) return true; + if (u == 0) { + return true; + } + if (s.st_mode & S_IROTH) { + return true; + } + if (s.st_mode & S_IRUSR && s.st_uid == u) { + return true; + } + if (s.st_mode & S_IRGRP && + (s.st_gid == g + || userLookup.getEntry(u)->group == s.st_gid + || groupLookup.getEntry(s.st_gid)->hasMember(u))) + { + return true; + } return false; } bool ModeCheck::WritableBy(const struct stat & s, uid_t u, gid_t g) const { - if (u == 0) return true; - if (s.st_mode & S_IWOTH) return true; - if (s.st_mode & S_IWUSR && s.st_uid == u) return true; - if (s.st_mode & S_IWGRP && (s.st_gid == g || userLookup.getEntry(u)->group == s.st_gid || groupLookup.getEntry(s.st_gid)->hasMember(u))) return true; + if (u == 0) { + return true; + } + if (s.st_mode & S_IWOTH) { + return true; + } + if (s.st_mode & S_IWUSR && s.st_uid == u) { + return true; + } + if (s.st_mode & S_IWGRP && + (s.st_gid == g + || userLookup.getEntry(u)->group == s.st_gid + || groupLookup.getEntry(s.st_gid)->hasMember(u))) { + return true; + } return false; } bool ModeCheck::ExecutableBy(const struct stat & s, uid_t u, gid_t g) const { - if (u == 0 && (s.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR))) return true; - if (s.st_mode & S_IXOTH) return true; - if (s.st_mode & S_IXUSR && s.st_uid == u) return true; - if (s.st_mode & S_IXGRP && (s.st_gid == g || userLookup.getEntry(u)->group == s.st_gid || groupLookup.getEntry(s.st_gid)->hasMember(u))) return true; + if (u == 0 && (s.st_mode & (S_IXOTH | S_IXGRP | S_IXUSR))) { + return true; + } + if (s.st_mode & S_IXOTH) { + return true; + } + if (s.st_mode & S_IXUSR && s.st_uid == u) { + return true; + } + if (s.st_mode & S_IXGRP && + (s.st_gid == g + || userLookup.getEntry(u)->group == s.st_gid + || groupLookup.getEntry(s.st_gid)->hasMember(u))) { + return true; + } return false; } diff --git a/netfs/fuse/fuseAppBase.cpp b/netfs/fuse/fuseAppBase.cpp index 4485aec..01ec8e1 100644 --- a/netfs/fuse/fuseAppBase.cpp +++ b/netfs/fuse/fuseAppBase.cpp @@ -149,7 +149,7 @@ int FuseAppBase::lock(const char *, struct fuse_file_info *, int, struct flock * { return -ENOSYS; } -// NOLINTNEXTLINE(modernize-avoid-c-arrays) +// NOLINTNEXTLINE(modernize-avoid-c-arrays, hicpp-avoid-c-arrays) int FuseAppBase::utimens(const char *, const struct timespec[2]) { return -ENOSYS; @@ -190,8 +190,11 @@ void FuseAppBase::log(int level, const char * message) const noexcept void FuseAppBase::logf(int level, const char * fmt, ...) const noexcept { va_list args; + // NOLINTNEXTLINE(hicpp-no-array-decay) va_start(args, fmt); + // NOLINTNEXTLINE(hicpp-no-array-decay) vlogf(level, fmt, args); + // NOLINTNEXTLINE(hicpp-no-array-decay) va_end(args); } diff --git a/netfs/fuse/fuseMisc.cpp b/netfs/fuse/fuseMisc.cpp index 3d72f5c..cbe48af 100644 --- a/netfs/fuse/fuseMisc.cpp +++ b/netfs/fuse/fuseMisc.cpp @@ -113,7 +113,7 @@ NetFS::FuseApp::rename(const char * p1, const char * p2) } int -// NOLINTNEXTLINE(modernize-avoid-c-arrays) +// NOLINTNEXTLINE(modernize-avoid-c-arrays,hicpp-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 731327f..c21711c 100644 --- a/netfs/fuse/netfs.cpp +++ b/netfs/fuse/netfs.cpp @@ -3,23 +3,28 @@ class FuseImpl : public NetFS::FuseApp { public: - FuseImpl(const Ice::StringSeq & a) : + explicit FuseImpl(const Ice::StringSeq & a) : NetFS::FuseApp(a) { openlog("netfs", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_USER); } + FuseImpl(const FuseImpl &) = delete; + FuseImpl(FuseImpl &&) = delete; ~FuseImpl() override { closelog(); } + void operator=(const FuseImpl &) = delete; + void operator=(FuseImpl &&) = delete; + struct fuse_context * fuse_get_context() override { return ::fuse_get_context(); } - // NOLINTNEXTLINE(modernize-avoid-c-arrays) + // NOLINTNEXTLINE(modernize-avoid-c-arrays, hicpp-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); diff --git a/netfs/ice/typeConverter.cpp b/netfs/ice/typeConverter.cpp index 373877c..7619063 100644 --- a/netfs/ice/typeConverter.cpp +++ b/netfs/ice/typeConverter.cpp @@ -19,7 +19,7 @@ inline void safeAssign(T & t, const S & s) struct stat EntryTypeConverter::convert(const NetFS::Attr & a) const { - struct stat s; + struct stat s {}; s.st_dev = a.dev; s.st_ino = a.inode; s.st_mode = a.mode; @@ -45,7 +45,7 @@ EntryTypeConverter::convert(const NetFS::Attr & a) const struct statvfs TypeConverter::convert(const NetFS::VFS & v) const { - struct statvfs vfs; + struct statvfs vfs {}; vfs.f_bsize = v.blockSize; vfs.f_frsize = v.fragmentSize; vfs.f_blocks = v.blocks; @@ -63,7 +63,7 @@ TypeConverter::convert(const NetFS::VFS & v) const NetFS::Attr EntryTypeConverter::convert(const struct stat & s) const { - NetFS::Attr a; + NetFS::Attr a {}; a.dev = s.st_dev; a.inode = s.st_ino; a.mode = s.st_mode; @@ -83,7 +83,7 @@ EntryTypeConverter::convert(const struct stat & s) const NetFS::VFS TypeConverter::convert(const struct statvfs & s) const { - NetFS::VFS t; + NetFS::VFS t {}; safeAssign(t.blockSize, s.f_bsize); safeAssign(t.fragmentSize, s.f_frsize); t.blocks = s.f_blocks; diff --git a/netfs/lib/entCache.cpp b/netfs/lib/entCache.cpp index 25e8902..0e8e638 100644 --- a/netfs/lib/entCache.cpp +++ b/netfs/lib/entCache.cpp @@ -71,8 +71,8 @@ EntCache::fillCache() const Lock(lock); setpwent(); idcache.clear(); - std::array buf; - struct passwd pwbuf, * pwp; + std::array buf {}; + struct passwd pwbuf {}, * pwp; while (getpwent_r(&pwbuf, buf.data(), buf.size(), &pwp) == 0) { idcache.insert(std::make_shared(pwp->pw_uid, pwp->pw_name, pwp->pw_gid)); } @@ -92,9 +92,9 @@ EntCache::fillCache() const { Lock(lock); setgrent(); - std::array buf; + std::array buf {}; idcache.clear(); - struct group grpbuf, * grp; + struct group grpbuf {}, * grp; EntCache instance; while (getgrent_r(&grpbuf, buf.data(), buf.size(), &grp) == 0) { auto g = std::make_shared(grp->gr_gid, grp->gr_name); diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam index 3f82c04..c76f229 100644 --- a/netfs/unittests/Jamfile.jam +++ b/netfs/unittests/Jamfile.jam @@ -5,6 +5,9 @@ lib boost_utf : : boost_unit_test_framework ; project : requirements tidy:misc-non-private-member-variables-in-classes + tidy:hicpp-special-member-functions + tidy:hicpp-explicit-conversions + tidy:hicpp-member-init ; path-constant me : . ; diff --git a/netfs/unittests/mockFuse.cpp b/netfs/unittests/mockFuse.cpp index 9e9ac87..8558b4c 100644 --- a/netfs/unittests/mockFuse.cpp +++ b/netfs/unittests/mockFuse.cpp @@ -3,7 +3,9 @@ FuseMock::FuseMock(std::string ep, Ice::StringSeq a) : NetFS::FuseApp(std::move(a)), - testEndpoint(std::move(ep)) + ops({}), + testEndpoint(std::move(ep)), + context({}) { ::memset(&context, 0, sizeof(fuse_context)); context.pid = getpid(); @@ -18,7 +20,7 @@ FuseMock::fuse_get_context() } int -// NOLINTNEXTLINE(modernize-avoid-c-arrays) +// NOLINTNEXTLINE(modernize-avoid-c-arrays, hicpp-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) { diff --git a/netfs/unittests/testEdgeCases.cpp b/netfs/unittests/testEdgeCases.cpp index 1c6c3e6..4fd65ab 100644 --- a/netfs/unittests/testEdgeCases.cpp +++ b/netfs/unittests/testEdgeCases.cpp @@ -16,26 +16,26 @@ BOOST_AUTO_TEST_CASE ( createAndDaemonRestart ) (rootDir / "test").string() }); - struct statvfs s; + struct statvfs s {}; BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); const char * fileName = "/createMe"; BOOST_TEST_CHECKPOINT("Create a new file"); - struct fuse_file_info fh; + struct fuse_file_info fh {}; memset(&fh, 0, sizeof(fh)); fh.flags = O_WRONLY | O_CREAT | O_APPEND; BOOST_REQUIRE_EQUAL(0, fuse.fuse->create(fileName, 0100644, &fh)); BOOST_REQUIRE(fh.fh); BOOST_TEST_CHECKPOINT("Fetch file attributes"); - struct stat st; + struct stat st {}; BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh)); BOOST_REQUIRE_EQUAL(st.st_size, 0); BOOST_REQUIRE_EQUAL(st.st_uid, getuid()); BOOST_REQUIRE_EQUAL(st.st_gid, getgid()); BOOST_TEST_CHECKPOINT("Write some data"); - std::array someData; + std::array someData {}; for (auto & d : someData) { d = rand(); } @@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE( noDaemonAtStartUp ) (rootDir / "test").string() }); - struct statvfs s; + struct statvfs s {}; BOOST_REQUIRE_EQUAL(-EIO, fuse.fuse->statfs("/", &s)); MockDaemonHost daemon(testEndpoint, { "--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string() @@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE ( daemonUnavailableAfterUse ) (rootDir / "defaultFuse.xml:testvol").string(), (rootDir / "test").string() }); - struct statvfs s; + struct statvfs s {}; { MockDaemonHost daemon(testEndpoint, { "--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string() @@ -111,7 +111,7 @@ BOOST_AUTO_TEST_CASE( manyThreads ) std::atomic_uint success = 0; for (int x = 0; x < 20; x++) { ths.emplace_back([&] { - struct statvfs s; + struct statvfs s {}; while(running) { if (fuse.fuse->statfs("/", &s) == 0) { success++; diff --git a/netfs/unittests/testGlacier.cpp b/netfs/unittests/testGlacier.cpp index 900a531..44f52f4 100644 --- a/netfs/unittests/testGlacier.cpp +++ b/netfs/unittests/testGlacier.cpp @@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE ( withRouter ) "--Ice.Default.Router=Glacier2/router:tcp -h localhost -p 14063" }); - struct statvfs s; + struct statvfs s {}; BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); } } -- cgit v1.2.3