Fix clang-tidy warnings

This commit is contained in:
Sebastian Messmer 2018-10-14 22:26:30 +02:00
parent f4be42d892
commit 4b26c67146
29 changed files with 56 additions and 59 deletions

View File

@ -14,7 +14,7 @@ namespace cpputils {
struct FakeKey { struct FakeKey {
static FakeKey FromString(const std::string& keyData) { static FakeKey FromString(const std::string& keyData) {
return FakeKey{static_cast<uint64_t>(std::atoi(keyData.c_str()))}; return FakeKey{static_cast<uint64_t>(std::strtol(keyData.c_str(), nullptr, 10))};
} }
static constexpr unsigned int BINARY_LENGTH = sizeof(uint64_t); static constexpr unsigned int BINARY_LENGTH = sizeof(uint64_t);

View File

@ -47,21 +47,25 @@ Data Data::LoadFromStream(istream &stream, size_t size) {
Data Data::FromString(const std::string &data, unique_ref<Allocator> allocator) { Data Data::FromString(const std::string &data, unique_ref<Allocator> allocator) {
ASSERT(data.size() % 2 == 0, "hex encoded data cannot have odd number of characters"); ASSERT(data.size() % 2 == 0, "hex encoded data cannot have odd number of characters");
Data result(data.size() / 2, std::move(allocator)); Data result(data.size() / 2, std::move(allocator));
CryptoPP::StringSource(data, true, {
new CryptoPP::HexDecoder( CryptoPP::StringSource _1(data, true,
new CryptoPP::ArraySink(static_cast<CryptoPP::byte*>(result._data), result.size()) new CryptoPP::HexDecoder(
) new CryptoPP::ArraySink(static_cast<CryptoPP::byte*>(result._data), result.size())
); )
);
}
return result; return result;
} }
std::string Data::ToString() const { std::string Data::ToString() const {
std::string result; std::string result;
CryptoPP::ArraySource(static_cast<const CryptoPP::byte*>(_data), _size, true, {
new CryptoPP::HexEncoder( CryptoPP::ArraySource _1(static_cast<const CryptoPP::byte*>(_data), _size, true,
new CryptoPP::StringSink(result) new CryptoPP::HexEncoder(
) new CryptoPP::StringSink(result)
); )
);
}
ASSERT(result.size() == 2 * _size, "Created wrongly sized string"); ASSERT(result.size() == 2 * _size, "Created wrongly sized string");
return result; return result;
} }

View File

@ -59,11 +59,13 @@ template<size_t SIZE>
FixedSizeData<SIZE> FixedSizeData<SIZE>::FromString(const std::string &data) { FixedSizeData<SIZE> FixedSizeData<SIZE>::FromString(const std::string &data) {
ASSERT(data.size() == STRING_LENGTH, "Wrong string size for parsing FixedSizeData"); ASSERT(data.size() == STRING_LENGTH, "Wrong string size for parsing FixedSizeData");
FixedSizeData<SIZE> result; FixedSizeData<SIZE> result;
CryptoPP::StringSource(data, true, {
new CryptoPP::HexDecoder( CryptoPP::StringSource _1(data, true,
new CryptoPP::ArraySink(result._data, BINARY_LENGTH) new CryptoPP::HexDecoder(
) new CryptoPP::ArraySink(result._data, BINARY_LENGTH)
); )
);
}
return result; return result;
} }

View File

@ -15,7 +15,7 @@ inline std::unique_ptr<DST> dynamic_pointer_move(std::unique_ptr<SRC> &source) {
//TODO Deleter //TODO Deleter
DST *casted = dynamic_cast<DST*>(source.get()); DST *casted = dynamic_cast<DST*>(source.get());
if (casted != nullptr) { if (casted != nullptr) {
source.release(); std::ignore = source.release();
} }
return std::unique_ptr<DST>(casted); return std::unique_ptr<DST>(casted);
} }

View File

@ -108,7 +108,7 @@ private:
explicit unique_ref(std::unique_ptr<T, D> target) noexcept explicit unique_ref(std::unique_ptr<T, D> target) noexcept
: _target(std::move(target)) {} : _target(std::move(target)) {}
void _invariant() const { void _invariant() const noexcept {
// TODO Test performance impact of this // TODO Test performance impact of this
ASSERT(_target.get() != nullptr, "Member was moved out to another unique_ref. This instance is invalid."); ASSERT(_target.get() != nullptr, "Member was moved out to another unique_ref. This instance is invalid.");
} }

View File

@ -22,7 +22,7 @@ int set_filetime(const char *filepath, timespec lastAccessTime, timespec lastMod
} }
int get_filetime(const char *filepath, timespec* lastAccessTime, timespec* lastModificationTime) { int get_filetime(const char *filepath, timespec* lastAccessTime, timespec* lastModificationTime) {
struct ::stat attrib; struct ::stat attrib{};
int retval = ::stat(filepath, &attrib); int retval = ::stat(filepath, &attrib);
if (retval != 0) { if (retval != 0) {
return errno; return errno;

View File

@ -11,7 +11,7 @@ namespace time {
struct timespec now() { struct timespec now() {
auto now = system_clock::now().time_since_epoch(); auto now = system_clock::now().time_since_epoch();
struct timespec spec; struct timespec spec{};
spec.tv_sec = duration_cast<seconds>(now).count(); spec.tv_sec = duration_cast<seconds>(now).count();
spec.tv_nsec = duration_cast<nanoseconds>(now).count() % 1000000000; spec.tv_nsec = duration_cast<nanoseconds>(now).count() % 1000000000;
return spec; return spec;

View File

@ -139,7 +139,7 @@ public:
return *static_cast<ConcreteType*>(this); return *static_cast<ConcreteType*>(this);
} }
constexpr ConcreteType operator++(int) noexcept(noexcept(++std::declval<ConcreteType>())) { constexpr const ConcreteType operator++(int) noexcept(noexcept(++std::declval<ConcreteType>())) {
ConcreteType tmp = *static_cast<ConcreteType*>(this); ConcreteType tmp = *static_cast<ConcreteType*>(this);
++(*this); ++(*this);
return tmp; return tmp;
@ -150,7 +150,7 @@ public:
return *static_cast<ConcreteType*>(this); return *static_cast<ConcreteType*>(this);
} }
constexpr ConcreteType operator--(int) noexcept(noexcept(--std::declval<ConcreteType>())) { constexpr const ConcreteType operator--(int) noexcept(noexcept(--std::declval<ConcreteType>())) {
ConcreteType tmp = *static_cast<ConcreteType*>(this); ConcreteType tmp = *static_cast<ConcreteType*>(this);
--(*this); --(*this);
return tmp; return tmp;

View File

@ -44,8 +44,6 @@ using cpputils::unique_ref;
using cpputils::SCryptSettings; using cpputils::SCryptSettings;
using cpputils::Console; using cpputils::Console;
using cpputils::HttpClient; using cpputils::HttpClient;
using cpputils::DontEchoStdinToStdoutRAII;
using std::cin;
using std::cout; using std::cout;
using std::string; using std::string;
using std::endl; using std::endl;
@ -272,7 +270,7 @@ namespace cryfs {
if (minutes == none) { if (minutes == none) {
return none; return none;
} }
uint64_t millis = std::round(60000 * (*minutes)); uint64_t millis = std::llround(60000 * (*minutes));
return make_unique_ref<CallAfterTimeout>(milliseconds(millis), callback); return make_unique_ref<CallAfterTimeout>(milliseconds(millis), callback);
} }

View File

@ -12,10 +12,8 @@ using namespace cryfs::program_options;
using cryfs::CryConfigConsole; using cryfs::CryConfigConsole;
using cryfs::CryfsException; using cryfs::CryfsException;
using cryfs::ErrorCode; using cryfs::ErrorCode;
using std::pair;
using std::vector; using std::vector;
using std::cerr; using std::cerr;
using std::cout;
using std::endl; using std::endl;
using std::string; using std::string;
using boost::optional; using boost::optional;

View File

@ -8,7 +8,6 @@ using std::vector;
using std::string; using std::string;
using cpputils::unique_ref; using cpputils::unique_ref;
using cpputils::make_unique_ref; using cpputils::make_unique_ref;
using cpputils::FixedSizeData;
using blockstore::BlockStore2; using blockstore::BlockStore2;
using std::shared_ptr; using std::shared_ptr;
using std::make_shared; using std::make_shared;

View File

@ -5,7 +5,6 @@ using std::string;
using cpputils::unique_ref; using cpputils::unique_ref;
using cpputils::make_unique_ref; using cpputils::make_unique_ref;
using cpputils::Data; using cpputils::Data;
using cpputils::FixedSizeData;
using boost::optional; using boost::optional;
using boost::none; using boost::none;
using namespace cpputils::logging; using namespace cpputils::logging;

View File

@ -157,15 +157,15 @@ struct num_bytes_t final : cpputils::value_type::QuantityValueType<num_bytes_t,
}; };
struct stat_info final { struct stat_info final {
uint32_t nlink; uint32_t nlink{};
fspp::mode_t mode; fspp::mode_t mode;
fspp::uid_t uid; fspp::uid_t uid;
fspp::gid_t gid; fspp::gid_t gid;
fspp::num_bytes_t size; fspp::num_bytes_t size;
uint64_t blocks; uint64_t blocks{};
struct timespec atime; struct timespec atime{};
struct timespec mtime; struct timespec mtime{};
struct timespec ctime; struct timespec ctime{};
}; };
struct statvfs final { struct statvfs final {

View File

@ -147,4 +147,4 @@ TEST_F(DataNodeStoreTest, PhysicalBlockSize_Inner) {
auto node = nodeStore->createNewInnerNode(1, {leaf->blockId()}); auto node = nodeStore->createNewInnerNode(1, {leaf->blockId()});
auto block = blockStore->load(node->blockId()).value(); auto block = blockStore->load(node->blockId()).value();
EXPECT_EQ(BLOCKSIZE_BYTES, block->size()); EXPECT_EQ(BLOCKSIZE_BYTES, block->size());
} }

View File

@ -20,7 +20,6 @@ using cpputils::AES256_GCM;
using cpputils::AES256_CFB; using cpputils::AES256_CFB;
using cpputils::FakeAuthenticatedCipher; using cpputils::FakeAuthenticatedCipher;
using cpputils::Data;
using cpputils::DataFixture; using cpputils::DataFixture;
using cpputils::make_unique_ref; using cpputils::make_unique_ref;
using cpputils::unique_ref; using cpputils::unique_ref;

View File

@ -231,7 +231,9 @@ TEST_F(KnownBlockVersionsTest, checkAndUpdate_doesntAllowRollbackToOldClientWith
TEST_F(KnownBlockVersionsTest, saveAndLoad_empty) { TEST_F(KnownBlockVersionsTest, saveAndLoad_empty) {
TempFile stateFile(false); TempFile stateFile(false);
KnownBlockVersions(stateFile.path(), myClientId); {
KnownBlockVersions _1(stateFile.path(), myClientId);
}
EXPECT_TRUE(KnownBlockVersions(stateFile.path(), myClientId).checkAndUpdateVersion(clientId, blockId, 1)); EXPECT_TRUE(KnownBlockVersions(stateFile.path(), myClientId).checkAndUpdateVersion(clientId, blockId, 1));
} }

View File

@ -8,7 +8,6 @@
#endif #endif
#include "cpp-utils/assert/assert.h" #include "cpp-utils/assert/assert.h"
using testing::MatchesRegex;
using testing::HasSubstr; using testing::HasSubstr;
TEST(AssertTest_ReleaseBuild, DoesntThrowIfTrue) { TEST(AssertTest_ReleaseBuild, DoesntThrowIfTrue) {
@ -32,7 +31,7 @@ TEST(AssertTest_ReleaseBuild, AssertMessage) {
/*EXPECT_THAT(e.what(), MatchesRegex( /*EXPECT_THAT(e.what(), MatchesRegex(
R"(Assertion \[2==5\] failed in .*assert_release_test.cpp:27: my message)" R"(Assertion \[2==5\] failed in .*assert_release_test.cpp:27: my message)"
));*/ ));*/
EXPECT_TRUE(std::regex_search(e.what(), std::regex(R"(Assertion \[2==5\] failed in .*assert_release_test.cpp:27: my message)"))); EXPECT_TRUE(std::regex_search(e.what(), std::regex(R"(Assertion \[2==5\] failed in .*assert_release_test.cpp:26: my message)")));
} }
} }

View File

@ -12,20 +12,20 @@ void handle_exit_signal(char* argv[]) {
throw std::logic_error(argv[2]); throw std::logic_error(argv[2]);
} else if (kind == "nullptr") { } else if (kind == "nullptr") {
int* ptr = nullptr; int* ptr = nullptr;
*ptr = 5; *ptr = 5; // NOLINT
} else if (kind == "signal") { } else if (kind == "signal") {
#if defined(_MSC_VER) #if defined(_MSC_VER)
DWORD code = std::atoll(argv[2]); DWORD code = std::atoll(argv[2]);
::RaiseException(code, EXCEPTION_NONCONTINUABLE, 0, NULL); ::RaiseException(code, EXCEPTION_NONCONTINUABLE, 0, NULL);
#else #else
int code = std::atoi(argv[2]); int code = std::strtol(argv[2], nullptr, 10);
::raise(code); ::raise(code);
#endif #endif
} }
} }
int main(int argc, char* argv[]) { int main(int /*argc*/, char* argv[]) {
cpputils::showBacktraceOnCrash(); cpputils::showBacktraceOnCrash();
#if defined(_MSC_VER) #if defined(_MSC_VER)
// don't show windows error box // don't show windows error box

View File

@ -197,7 +197,7 @@ TEST_F(DataTest, Inequality_DifferentLastByte) {
#ifdef __x86_64__ #ifdef __x86_64__
TEST_F(DataTest, LargesizeSize) { TEST_F(DataTest, LargesizeSize) {
//Needs 64bit for representation. This value isn't in the size param list, because the list is also used for read/write checks. //Needs 64bit for representation. This value isn't in the size param list, because the list is also used for read/write checks.
uint64_t size = 4.5L*1024*1024*1024; uint64_t size = static_cast<uint64_t>(4.5L*1024*1024*1024);
Data data(size); Data data(size);
EXPECT_EQ(size, data.size()); EXPECT_EQ(size, data.size());
} }
@ -235,7 +235,7 @@ struct MockAllocator final : public Allocator {
class DataTestWithMockAllocator: public DataTest { class DataTestWithMockAllocator: public DataTest {
public: public:
char ptr_target; char ptr_target{};
unique_ref<MockAllocator> allocator = make_unique_ref<MockAllocator>(); unique_ref<MockAllocator> allocator = make_unique_ref<MockAllocator>();
MockAllocator* allocator_ptr = allocator.get(); MockAllocator* allocator_ptr = allocator.get();

View File

@ -3,7 +3,6 @@
using namespace cpputils::logging; using namespace cpputils::logging;
using std::string; using std::string;
using testing::MatchesRegex;
class LoggingLevelTest: public LoggingTest { class LoggingLevelTest: public LoggingTest {
public: public:

View File

@ -8,7 +8,6 @@
using namespace cpputils::logging; using namespace cpputils::logging;
using std::string; using std::string;
using testing::MatchesRegex;
TEST_F(LoggingTest, DefaultLoggerIsStderr) { TEST_F(LoggingTest, DefaultLoggerIsStderr) {
string output = captureStderr([]{ string output = captureStderr([]{

View File

@ -11,6 +11,6 @@ int main(int argc, char* argv[]) {
std::cout << argv[1]; std::cout << argv[1];
int exit_status = std::atoi(argv[2]); int exit_status = std::strtol(argv[2], nullptr, 10);
return exit_status; return exit_status;
} }

View File

@ -13,8 +13,8 @@ TEST(FiletimeTest, SetAndGetTime_ReturnsCorrectTime) {
int retval = set_filetime(file.path().string().c_str(), accessTime, modificationTime); int retval = set_filetime(file.path().string().c_str(), accessTime, modificationTime);
EXPECT_EQ(0, retval); EXPECT_EQ(0, retval);
struct timespec readAccessTime; struct timespec readAccessTime{};
struct timespec readModificationTime; struct timespec readModificationTime{};
retval = get_filetime(file.path().string().c_str(), &readAccessTime, &readModificationTime); retval = get_filetime(file.path().string().c_str(), &readAccessTime, &readModificationTime);
EXPECT_EQ(0, retval); EXPECT_EQ(0, retval);

View File

@ -35,11 +35,13 @@ private:
Data hexToBinary(const string &hex) { Data hexToBinary(const string &hex) {
ASSERT(hex.size()%2 == 0, "Hex codes need to have two characters per byte"); ASSERT(hex.size()%2 == 0, "Hex codes need to have two characters per byte");
Data result(hex.size()/2); Data result(hex.size()/2);
CryptoPP::StringSource(hex, true, {
new CryptoPP::HexDecoder( CryptoPP::StringSource _1(hex, true,
new CryptoPP::ArraySink(static_cast<CryptoPP::byte*>(result.data()), result.size()) new CryptoPP::HexDecoder(
) new CryptoPP::ArraySink(static_cast<CryptoPP::byte*>(result.data()), result.size())
); )
);
}
return result; return result;
} }

View File

@ -9,7 +9,6 @@ using cpputils::make_unique_ref;
using cpputils::DataFixture; using cpputils::DataFixture;
using cpputils::Data; using cpputils::Data;
using cpputils::EncryptionKey; using cpputils::EncryptionKey;
using cpputils::FixedSizeData;
using cpputils::AES128_CFB; using cpputils::AES128_CFB;
using cpputils::AES256_GCM; using cpputils::AES256_GCM;
using cpputils::Twofish256_GCM; using cpputils::Twofish256_GCM;

View File

@ -10,7 +10,7 @@ public:
const char *FILENAME = "/myfile"; const char *FILENAME = "/myfile";
struct ReadError { struct ReadError {
int error; int error{};
fspp::num_bytes_t read_bytes; fspp::num_bytes_t read_bytes;
}; };

View File

@ -2,7 +2,6 @@
#include "fspp/fs_interface/FuseErrnoException.h" #include "fspp/fs_interface/FuseErrnoException.h"
using ::testing::StrEq;
using ::testing::_; using ::testing::_;
using ::testing::Throw; using ::testing::Throw;
using ::testing::Return; using ::testing::Return;

View File

@ -1,7 +1,6 @@
#include "FuseStatfsTest.h" #include "FuseStatfsTest.h"
using std::function; using std::function;
using ::testing::StrEq;
using ::testing::_; using ::testing::_;
using ::testing::Invoke; using ::testing::Invoke;

View File

@ -10,7 +10,7 @@ public:
const char *FILENAME = "/myfile"; const char *FILENAME = "/myfile";
struct WriteError { struct WriteError {
int error; int error{};
fspp::num_bytes_t written_bytes; fspp::num_bytes_t written_bytes;
}; };