diff --git a/CMakeLists.txt b/CMakeLists.txt index bdcb9db..f7e23e9 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() @@ -179,8 +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" ",-readability-named-parameter" 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/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/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/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 { diff --git a/encfs/XmlReader.cpp b/encfs/XmlReader.cpp index b28c264..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, @@ -154,7 +166,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) { 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..27c6160 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; @@ -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 b79c801..e2b3a0b 100644 --- a/encfs/main.cpp +++ b/encfs/main.cpp @@ -557,8 +557,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, ""); @@ -622,7 +620,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; 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 {