From 8b46390028ee1752c8bca1fa89154439c308d33b Mon Sep 17 00:00:00 2001 From: Ben RUBSON Date: Sun, 29 Oct 2017 22:49:23 +0100 Subject: [PATCH 1/7] Make Travis use correct clang-tidy binary also reference FreeBSD clang-tidy bin name --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bdcb9db..38c3182 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,7 +166,7 @@ if (ENABLE_NLS) endif (ENABLE_NLS) if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.5) # Need 3.6 or above. - find_program(CLANG_TIDY_EXE NAMES "clang-tidy" "clang-tidy-4.0" DOC "Path to clang-tidy executable") + find_program(CLANG_TIDY_EXE NAMES "clang-tidy-4.0" "clang-tidy40" "clang-tidy" DOC "Path to clang-tidy executable") if(NOT CLANG_TIDY_EXE) message(STATUS "clang-tidy not found.") else() From e2ea0e4d2fed15c12c52e4ba4b88e657cd3375ad Mon Sep 17 00:00:00 2001 From: Ben RUBSON Date: Sun, 29 Oct 2017 22:58:51 +0100 Subject: [PATCH 2/7] Correct parentheses and brackets clang warnings --- encfs/MemoryPool.cpp | 2 +- encfs/readpassphrase.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/encfs/MemoryPool.cpp b/encfs/MemoryPool.cpp index ff28056..29a9daf 100644 --- a/encfs/MemoryPool.cpp +++ b/encfs/MemoryPool.cpp @@ -33,7 +33,7 @@ #include -#define BLOCKDATA(BLOCK) (unsigned char *)BLOCK->data->data +#define BLOCKDATA(BLOCK) (unsigned char *)(BLOCK)->data->data namespace encfs { diff --git a/encfs/readpassphrase.cpp b/encfs/readpassphrase.cpp index 2e5913c..d9d9319 100644 --- a/encfs/readpassphrase.cpp +++ b/encfs/readpassphrase.cpp @@ -116,8 +116,9 @@ restart: term.c_lflag &= ~(ECHO | ECHONL); } #ifdef VSTATUS - if (term.c_cc[VSTATUS] != _POSIX_VDISABLE) + if (term.c_cc[VSTATUS] != _POSIX_VDISABLE) { term.c_cc[VSTATUS] = _POSIX_VDISABLE; + } #endif (void)tcsetattr(input, _T_FLUSH, &term); } else { From 1254c686eaf9d591c56adc3cb38c8a46f28de66f Mon Sep 17 00:00:00 2001 From: Ben RUBSON Date: Thu, 2 Nov 2017 07:52:57 +0100 Subject: [PATCH 3/7] Correct misc-misplaced-widening-cast clang warnings --- CMakeLists.txt | 1 - encfs/BlockFileIO.cpp | 2 +- encfs/SSL_Cipher.cpp | 14 +++++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38c3182..7e961a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,7 +179,6 @@ if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.5) # Need 3.6 or abo ",-google-readability-todo" ",-google-runtime-int" ",-google-runtime-references" - ",-misc-misplaced-widening-cast" ",-misc-unused-parameters" ",-modernize-loop-convert" ",-readability-inconsistent-declaration-parameter-name" diff --git a/encfs/BlockFileIO.cpp b/encfs/BlockFileIO.cpp index b0eede1..71d2c05 100644 --- a/encfs/BlockFileIO.cpp +++ b/encfs/BlockFileIO.cpp @@ -251,7 +251,7 @@ ssize_t BlockFileIO::write(const IORequest &req) { unsigned char *inPtr = req.data; while (size != 0u) { blockReq.offset = blockNum * _blockSize; - int toCopy = min((size_t)(_blockSize - partialOffset), size); + size_t toCopy = min((size_t)_blockSize - (size_t)partialOffset, size); // if writing an entire block, or writing a partial block that requires // no merging with existing data.. diff --git a/encfs/SSL_Cipher.cpp b/encfs/SSL_Cipher.cpp index b530fdc..897eace 100644 --- a/encfs/SSL_Cipher.cpp +++ b/encfs/SSL_Cipher.cpp @@ -301,11 +301,11 @@ SSLKey::SSLKey(int keySize_, int ivLength_) { this->ivLength = ivLength_; pthread_mutex_init(&mutex, nullptr); buffer = (unsigned char *)OPENSSL_malloc(keySize + ivLength); - memset(buffer, 0, keySize + ivLength); + memset(buffer, 0, (size_t)keySize + (size_t)ivLength); // most likely fails unless we're running as root, or a user-page-lock // kernel patch is applied.. - mlock(buffer, keySize + ivLength); + mlock(buffer, (size_t)keySize + (size_t)ivLength); block_enc = EVP_CIPHER_CTX_new(); EVP_CIPHER_CTX_init(block_enc); @@ -320,10 +320,10 @@ SSLKey::SSLKey(int keySize_, int ivLength_) { } SSLKey::~SSLKey() { - memset(buffer, 0, keySize + ivLength); + memset(buffer, 0, (size_t)keySize + (size_t)ivLength); OPENSSL_free(buffer); - munlock(buffer, keySize + ivLength); + munlock(buffer, (size_t)keySize + (size_t)ivLength); keySize = 0; ivLength = 0; @@ -593,7 +593,7 @@ CipherKey SSL_Cipher::readKey(const unsigned char *data, checksum = (checksum << 8) | (unsigned int)data[i]; } - memcpy(tmpBuf, data + KEY_CHECKSUM_BYTES, _keySize + _ivLength); + memcpy(tmpBuf, data + KEY_CHECKSUM_BYTES, (size_t)_keySize + (size_t)_ivLength); streamDecode(tmpBuf, _keySize + _ivLength, checksum, masterKey); // check for success @@ -608,7 +608,7 @@ CipherKey SSL_Cipher::readKey(const unsigned char *data, std::shared_ptr key(new SSLKey(_keySize, _ivLength)); - memcpy(key->buffer, tmpBuf, _keySize + _ivLength); + memcpy(key->buffer, tmpBuf, (size_t)_keySize + (size_t)_ivLength); memset(tmpBuf, 0, sizeof(tmpBuf)); initKey(key, _blockCipher, _streamCipher, _keySize); @@ -652,7 +652,7 @@ bool SSL_Cipher::compareKey(const CipherKey &A, const CipherKey &B) const { rAssert(key1->keySize == _keySize); rAssert(key2->keySize == _keySize); - return memcmp(key1->buffer, key2->buffer, _keySize + _ivLength) == 0; + return memcmp(key1->buffer, key2->buffer, (size_t)_keySize + (size_t)_ivLength) == 0; } int SSL_Cipher::encodedKeySize() const { From a3d6b6f3132ff27207fe0e8753a50c4bbfd78556 Mon Sep 17 00:00:00 2001 From: Ben RUBSON Date: Thu, 2 Nov 2017 08:06:51 +0100 Subject: [PATCH 4/7] Correct unnecessary-value-param clang warnings --- encfs/base64.cpp | 2 +- encfs/base64.h | 2 +- encfs/encfs.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/encfs/base64.cpp b/encfs/base64.cpp index 37b6d6c..c14ea95 100644 --- a/encfs/base64.cpp +++ b/encfs/base64.cpp @@ -252,7 +252,7 @@ bool B64StandardDecode(unsigned char *out, const unsigned char *in, int inLen) { // If you want to use an alternate alphabet, change the characters here const static char encodeLookup[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -std::string B64StandardEncode(std::vector inputBuffer) { +std::string B64StandardEncode(const std::vector &inputBuffer) { std::string encodedString; encodedString.reserve(B256ToB64Bytes(inputBuffer.size())); long temp; diff --git a/encfs/base64.h b/encfs/base64.h index 796cfd6..4ec5f2d 100644 --- a/encfs/base64.h +++ b/encfs/base64.h @@ -73,7 +73,7 @@ void AsciiToB32(unsigned char *out, const unsigned char *in, int length); bool B64StandardDecode(unsigned char *out, const unsigned char *in, int inputLen); -std::string B64StandardEncode(std::vector input); +std::string B64StandardEncode(const std::vector &input); } // namespace encfs diff --git a/encfs/encfs.cpp b/encfs/encfs.cpp index 16c3ae6..77d81b9 100644 --- a/encfs/encfs.cpp +++ b/encfs/encfs.cpp @@ -135,7 +135,7 @@ static void checkCanary(const std::shared_ptr &fnode) { // helper function -- apply a functor to a node static int withFileNode(const char *opName, const char *path, struct fuse_file_info *fi, - function op) { + const function &op) { EncFS_Context *ctx = context(); int res = -EIO; From 6cb5078cb21c8c10d4233ab9f1829f97c62b2c9f Mon Sep 17 00:00:00 2001 From: Ben RUBSON Date: Thu, 2 Nov 2017 08:28:22 +0100 Subject: [PATCH 5/7] Correct explicit-constructor clang warning --- encfs/XmlReader.cpp | 2 +- encfs/autosprintf.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/encfs/XmlReader.cpp b/encfs/XmlReader.cpp index b28c264..18d0cef 100644 --- a/encfs/XmlReader.cpp +++ b/encfs/XmlReader.cpp @@ -154,7 +154,7 @@ class XmlNode : virtual public XmlValue { const tinyxml2::XMLElement *element; public: - XmlNode(const tinyxml2::XMLElement *element_) + explicit XmlNode(const tinyxml2::XMLElement *element_) : XmlValue(safeValueForNode(element_)), element(element_) {} ~XmlNode() override = default; diff --git a/encfs/autosprintf.h b/encfs/autosprintf.h index 9303168..cf91dbd 100644 --- a/encfs/autosprintf.h +++ b/encfs/autosprintf.h @@ -48,8 +48,8 @@ class autosprintf { /* Destructor: frees the temporarily allocated string. */ ~autosprintf(); /* Conversion to string. */ - operator char*() const; - operator std::string() const; + explicit operator char*() const; + explicit operator std::string() const; /* Output to an ostream. */ friend inline std::ostream& operator<<(std::ostream& stream, const autosprintf& tmp) { From 135fe9e98b2419d06f51dc1d86e4200c3a0fb61e Mon Sep 17 00:00:00 2001 From: Ben RUBSON Date: Thu, 2 Nov 2017 08:35:30 +0100 Subject: [PATCH 6/7] Correct unused-parameter warnings --- CMakeLists.txt | 1 - encfs/encfs.cpp | 4 ++++ encfs/main.cpp | 3 --- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e961a6..f7e23e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,7 +179,6 @@ if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 3.5) # Need 3.6 or abo ",-google-readability-todo" ",-google-runtime-int" ",-google-runtime-references" - ",-misc-unused-parameters" ",-modernize-loop-convert" ",-readability-inconsistent-declaration-parameter-name" ",-readability-named-parameter" diff --git a/encfs/encfs.cpp b/encfs/encfs.cpp index 77d81b9..27c6160 100644 --- a/encfs/encfs.cpp +++ b/encfs/encfs.cpp @@ -230,6 +230,10 @@ int encfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *finfo) { EncFS_Context *ctx = context(); + //unused parameters + (void)offset; + (void)finfo; + int res = ESUCCESS; std::shared_ptr FSRoot = ctx->getRoot(&res); if (!FSRoot) { diff --git a/encfs/main.cpp b/encfs/main.cpp index 5421096..37ec751 100644 --- a/encfs/main.cpp +++ b/encfs/main.cpp @@ -556,8 +556,6 @@ void *encfs_init(fuse_conn_info *conn) { return (void *)ctx; } -void encfs_destroy(void *_ctx) {} - int main(int argc, char *argv[]) { #if defined(ENABLE_NLS) && defined(LOCALEDIR) setlocale(LC_ALL, ""); @@ -621,7 +619,6 @@ int main(int argc, char *argv[]) { // encfs_oper.releasedir = encfs_releasedir; // encfs_oper.fsyncdir = encfs_fsyncdir; encfs_oper.init = encfs_init; - encfs_oper.destroy = encfs_destroy; // encfs_oper.access = encfs_access; encfs_oper.create = encfs_create; encfs_oper.ftruncate = encfs_ftruncate; From 4e19edfd561b5b099e99055412960c03b70cf232 Mon Sep 17 00:00:00 2001 From: Ben RUBSON Date: Thu, 2 Nov 2017 08:44:14 +0100 Subject: [PATCH 7/7] Correct ato* clang warnings --- encfs/FileUtils.cpp | 12 ++++++------ encfs/XmlReader.cpp | 26 +++++++++++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/encfs/FileUtils.cpp b/encfs/FileUtils.cpp index 0431501..58e91a9 100644 --- a/encfs/FileUtils.cpp +++ b/encfs/FileUtils.cpp @@ -644,7 +644,7 @@ static Cipher::CipherAlgorithm selectCipherAlgorithm() { cout << "\n" << _("Enter the number corresponding to your choice: "); char answer[10]; char *res = fgets(answer, sizeof(answer), stdin); - int cipherNum = (res == nullptr ? 0 : atoi(answer)); + int cipherNum = (res == nullptr ? 0 : (int)strtol(answer, nullptr, 10)); cout << "\n"; if (cipherNum < 1 || cipherNum > (int)algorithms.size()) { @@ -688,7 +688,7 @@ static Interface selectNameCoding() { cout << "\n" << _("Enter the number corresponding to your choice: "); char answer[10]; char *res = fgets(answer, sizeof(answer), stdin); - int algNum = (res == nullptr ? 0 : atoi(answer)); + int algNum = (res == nullptr ? 0 : (int)strtol(answer, nullptr, 10)); cout << "\n"; if (algNum < 1 || algNum > (int)algorithms.size()) { @@ -755,7 +755,7 @@ static int selectKeySize(const Cipher::CipherAlgorithm &alg) { char answer[10]; char *res = fgets(answer, sizeof(answer), stdin); - int keySize = (res == nullptr ? 0 : atoi(answer)); + int keySize = (res == nullptr ? 0 : (int)strtol(answer, nullptr, 10)); cout << "\n"; keySize = alg.keyLength.closest(keySize); @@ -795,8 +795,8 @@ static int selectBlockSize(const Cipher::CipherAlgorithm &alg) { char *res = fgets(answer, sizeof(answer), stdin); cout << "\n"; - if (res != nullptr && atoi(answer) >= alg.blockSize.min()) { - blockSize = atoi(answer); + if (res != nullptr && (int)strtol(answer, nullptr, 10) >= alg.blockSize.min()) { + blockSize = (int)strtol(answer, nullptr, 10); } blockSize = alg.blockSize.closest(blockSize); @@ -900,7 +900,7 @@ static void selectBlockMAC(int *macBytes, int *macRandBytes, bool forceMac) { char *res = fgets(answer, sizeof(answer), stdin); cout << "\n"; - randSize = (res == nullptr ? 0 : atoi(answer)); + randSize = (res == nullptr ? 0 : (int)strtol(answer, nullptr, 10)); if (randSize < 0) { randSize = 0; } diff --git a/encfs/XmlReader.cpp b/encfs/XmlReader.cpp index 18d0cef..770cc96 100644 --- a/encfs/XmlReader.cpp +++ b/encfs/XmlReader.cpp @@ -23,6 +23,7 @@ #include // for remove_if #include // for NULL #include // for ifstream +#include #include // for shared_ptr #include // for ostringstream @@ -60,7 +61,15 @@ bool XmlValue::read(const char *path, int *out) const { return false; } - *out = atoi(value->text().c_str()); + char * e; + long lout = strtol(value->text().c_str(), &e, 10); + if (*e != '\0') { + return false; + } + if (lout < std::numeric_limits::min() || lout > std::numeric_limits::max()) { + return false; + } + *out = (int)lout; return true; } @@ -70,8 +79,9 @@ bool XmlValue::read(const char *path, long *out) const { return false; } - *out = atol(value->text().c_str()); - return true; + char * e; + *out = strtol(value->text().c_str(), &e, 10); + return (*e == '\0'); } bool XmlValue::read(const char *path, double *out) const { @@ -80,8 +90,9 @@ bool XmlValue::read(const char *path, double *out) const { return false; } - *out = atof(value->text().c_str()); - return true; + char * e; + *out = strtod(value->text().c_str(), &e); + return (*e == '\0'); } bool XmlValue::read(const char *path, bool *out) const { @@ -90,8 +101,9 @@ bool XmlValue::read(const char *path, bool *out) const { return false; } - *out = (atoi(value->text().c_str()) != 0); - return true; + char * e; + *out = (strtol(value->text().c_str(), &e, 10) != 0); + return (*e == '\0'); } bool XmlValue::readB64(const char *path, unsigned char *data,