From b606ef122b00f3056ad4c9740992fa6e0c0d1a99 Mon Sep 17 00:00:00 2001 From: Valient Gough Date: Mon, 21 Oct 2013 05:38:54 +0000 Subject: [PATCH] cleanup warnings from cppcheck git-svn-id: http://encfs.googlecode.com/svn/trunk@124 db9cf616-1c43-0410-9cb8-a902689de0d6 --- base/ConfigReader.cpp | 35 ----------------------------------- base/ConfigReader.h | 2 -- cipher/CipherKey.cpp | 3 ++- cipher/CipherKey.h | 2 +- cipher/CipherV1.cpp | 6 +++--- cipher/CipherV1.h | 4 ++-- cipher/botan.cpp | 2 +- cipher/openssl.cpp | 4 ++-- encfs/main.cpp | 25 ++++++++++++++++--------- fs/BlockFileIO.cpp | 2 +- fs/CipherFileIO.cpp | 2 +- fs/Context.cpp | 8 ++++---- fs/Context.h | 4 ++-- fs/DirNode.cpp | 4 ++-- fs/DirNode.h | 2 +- fs/FileNode.cpp | 2 +- fs/MemFileIO.cpp | 5 ----- fs/RawFileIO.cpp | 5 ----- fs/encfs.cpp | 2 +- 19 files changed, 40 insertions(+), 79 deletions(-) diff --git a/base/ConfigReader.cpp b/base/ConfigReader.cpp index 18378f4..8339071 100644 --- a/base/ConfigReader.cpp +++ b/base/ConfigReader.cpp @@ -92,41 +92,6 @@ bool ConfigReader::loadFromVar(ConfigVar &in) { return true; } -bool ConfigReader::save(const char *fileName) const { - // write everything to a ConfigVar, then output to disk - ConfigVar out = toVar(); - - int fd = ::open(fileName, O_RDWR | O_CREAT, 0640); - if (fd >= 0) { - int retVal = ::write(fd, out.buffer(), out.size()); - close(fd); - if (retVal != out.size()) { - LOG(ERROR) << "Error writing to config file " << fileName; - return false; - } - } else { - LOG(ERROR) << "Unable to open or create file " << fileName; - return false; - } - - return true; -} - -ConfigVar ConfigReader::toVar() const { - // write everything to a ConfigVar, then output to disk - ConfigVar out; - out.writeInt(vars.size()); - map::const_iterator it; - for (it = vars.begin(); it != vars.end(); ++it) { - out.writeInt(it->first.size()); - out.write((byte *)it->first.data(), it->first.size()); - out.writeInt(it->second.size()); - out.write((byte *)it->second.buffer(), it->second.size()); - } - - return out; -} - ConfigVar ConfigReader::operator[](const std::string &varName) const { // read only map::const_iterator it = vars.find(varName); diff --git a/base/ConfigReader.h b/base/ConfigReader.h index c53fe6d..4fa15d0 100644 --- a/base/ConfigReader.h +++ b/base/ConfigReader.h @@ -51,9 +51,7 @@ class ConfigReader { ~ConfigReader(); bool load(const char *fileName); - bool save(const char *fileName) const; - ConfigVar toVar() const; bool loadFromVar(ConfigVar &var); ConfigVar operator[](const std::string &varName) const; diff --git a/cipher/CipherKey.cpp b/cipher/CipherKey.cpp index c2e329f..1e95501 100644 --- a/cipher/CipherKey.cpp +++ b/cipher/CipherKey.cpp @@ -43,9 +43,10 @@ CipherKey::CipherKey(const CipherKey &src) CipherKey::~CipherKey() {} -void CipherKey::operator=(const CipherKey &src) { +CipherKey &CipherKey::operator=(const CipherKey &src) { _mem = src._mem; _valid = src._valid; + return *this; } byte *CipherKey::data() const { return !_mem ? NULL : _mem->data(); } diff --git a/cipher/CipherKey.h b/cipher/CipherKey.h index 9fc5e9e..835782f 100644 --- a/cipher/CipherKey.h +++ b/cipher/CipherKey.h @@ -38,7 +38,7 @@ class CipherKey { CipherKey(const CipherKey &src); ~CipherKey(); - void operator=(const CipherKey &src); + CipherKey &operator=(const CipherKey &src); byte *data() const; int size() const; diff --git a/cipher/CipherV1.cpp b/cipher/CipherV1.cpp index 82b74f1..54f2a54 100644 --- a/cipher/CipherV1.cpp +++ b/cipher/CipherV1.cpp @@ -231,7 +231,7 @@ shared_ptr CipherV1::New(const Interface &iface, int keyLen) { return result; } -CipherV1::CipherV1() {} +CipherV1::CipherV1() : _keySize(0), _ivLength(0), _keySet(false) {} bool CipherV1::initCiphers(const Interface &iface, const Interface &realIface, int keyLength) { @@ -471,7 +471,7 @@ CipherKey CipherV1::readKey(const byte *data, bool checkKey) { return key; } -void CipherV1::writeKey(const CipherKey &ckey, byte *out) { +void CipherV1::writeKey(const CipherKey &ckey, byte *out) const { rAssert(_keySet); SecureMem tmpBuf(ckey.size()); @@ -490,7 +490,7 @@ void CipherV1::writeKey(const CipherKey &ckey, byte *out) { memcpy(out + KEY_CHECKSUM_BYTES, tmpBuf.data(), tmpBuf.size()); } -std::string CipherV1::encodeAsString(const CipherKey &key) { +std::string CipherV1::encodeAsString(const CipherKey &key) const { rAssert(_keySet); int encodedSize = encodedKeySize(); vector buf(encodedSize); diff --git a/cipher/CipherV1.h b/cipher/CipherV1.h index 3a197d4..26b72a4 100644 --- a/cipher/CipherV1.h +++ b/cipher/CipherV1.h @@ -136,10 +136,10 @@ class CipherV1 { CipherKey readKey(const byte *data, bool checkKey); // Encrypt and write the given key. - void writeKey(const CipherKey &key, byte *data); + void writeKey(const CipherKey &key, byte *data) const; // Encrypt and store a key as a string. - std::string encodeAsString(const CipherKey &key); + std::string encodeAsString(const CipherKey &key) const; // meta-data about the cypher int keySize() const; diff --git a/cipher/botan.cpp b/cipher/botan.cpp index e074c67..5d6516e 100644 --- a/cipher/botan.cpp +++ b/cipher/botan.cpp @@ -121,7 +121,7 @@ class BotanBlockCipher : public BlockCipher { shared_ptr decryptor; public: - BotanBlockCipher() {} + BotanBlockCipher() : encryption(nullptr), decryption(nullptr) {} virtual ~BotanBlockCipher() {} bool rekey(const CipherKey& key, const string& cipherMode) { diff --git a/cipher/openssl.cpp b/cipher/openssl.cpp index 71f0ed6..8d94e4b 100644 --- a/cipher/openssl.cpp +++ b/cipher/openssl.cpp @@ -97,9 +97,9 @@ class OpenSSLCipher : public BlockCipher { static bool randomize(CipherKey *key) { int result = RAND_bytes(key->data(), key->size()); if (result != 1) { - char errStr[120]; // specs require string at least 120 bytes long.. unsigned long errVal = 0; if ((errVal = ERR_get_error()) != 0) + char errStr[120]; // specs require string at least 120 bytes long.. LOG(ERROR) << "openssl error: " << ERR_error_string(errVal, errStr); return false; @@ -118,9 +118,9 @@ class OpenSSLCipher : public BlockCipher { #endif int result = RAND_pseudo_bytes(out, length); if (result != 1) { - char errStr[120]; // specs require string at least 120 bytes long.. unsigned long errVal = 0; if ((errVal = ERR_get_error()) != 0) + char errStr[120]; // specs require string at least 120 bytes long.. LOG(ERROR) << "openssl error: " << ERR_error_string(errVal, errStr); return false; diff --git a/encfs/main.cpp b/encfs/main.cpp index 90c7783..ae8a84b 100644 --- a/encfs/main.cpp +++ b/encfs/main.cpp @@ -53,10 +53,6 @@ extern "C" void fuse_unmount_compat22(const char *mountpoint); #define fuse_unmount fuse_unmount_compat22 -#ifndef MAX -inline static int MAX(int a, int b) { return (a > b) ? a : b; } -#endif - using namespace encfs; using gnu::autosprintf; using std::cerr; @@ -84,7 +80,7 @@ struct EncFS_Args { // In case someone sends me a log dump, I want to know how what options are // in effect. Not internationalized, since it is something that is mostly // useful for me! - string toString() { + string toString() const { ostringstream ss; ss << (isDaemon ? "(daemon) " : "(fg) "); ss << (isThreaded ? "(threaded) " : "(UP) "); @@ -102,7 +98,17 @@ struct EncFS_Args { return ss.str(); } - EncFS_Args() : opts(new EncFS_Opts()) {} + EncFS_Args() + : isDaemon(false), + isThreaded(false), + isVerbose(false), + idleTimeout(0), + fuseArgc(0), + opts(new EncFS_Opts()) { + for (int i = 0; i < MaxFuseArgs; ++i) { + fuseArgv[i] = nullptr; + } + } }; static int oldStderr = STDERR_FILENO; @@ -420,7 +426,8 @@ static bool processArgs(int argc, char *argv[], static void *idleMonitor(void *); void *encfs_init(fuse_conn_info *conn) { - EncFS_Context *ctx = (EncFS_Context *)fuse_get_context()->private_data; + EncFS_Context *ctx = + static_cast(fuse_get_context()->private_data); // set fuse connection options conn->async_read = true; @@ -448,7 +455,7 @@ void *encfs_init(fuse_conn_info *conn) { } void encfs_destroy(void *_ctx) { - EncFS_Context *ctx = (EncFS_Context *)_ctx; + EncFS_Context *ctx = static_cast(_ctx); if (ctx->args->idleTimeout > 0) { ctx->running = false; @@ -667,7 +674,7 @@ const int ActivityCheckInterval = 10; static bool unmountFS(EncFS_Context *ctx); static void *idleMonitor(void *_arg) { - EncFS_Context *ctx = (EncFS_Context *)_arg; + EncFS_Context *ctx = static_cast(_arg); shared_ptr arg = ctx->args; const int timeoutCycles = 60 * arg->idleTimeout / ActivityCheckInterval; diff --git a/fs/BlockFileIO.cpp b/fs/BlockFileIO.cpp index c4f63ad..93de416 100644 --- a/fs/BlockFileIO.cpp +++ b/fs/BlockFileIO.cpp @@ -97,13 +97,13 @@ ssize_t BlockFileIO::read(const IORequest &req) const { int partialOffset = req.offset % _blockSize; off_t blockNum = req.offset / _blockSize; - ssize_t result = 0; if (partialOffset == 0 && req.dataLen <= _blockSize) { // read completely within a single block -- can be handled as-is by // readOneBloc(). return cacheReadOneBlock(req); } else { + ssize_t result = 0; size_t size = req.dataLen; // if the request is larger then a block, then request each block diff --git a/fs/CipherFileIO.cpp b/fs/CipherFileIO.cpp index f567c98..dc63ffb 100644 --- a/fs/CipherFileIO.cpp +++ b/fs/CipherFileIO.cpp @@ -254,8 +254,8 @@ ssize_t CipherFileIO::readOneBlock(const IORequest &req) const { int maxReadSize = req.dataLen; readSize = base->read(tmpReq); - bool ok; if (readSize > 0) { + bool ok; if (headerLen != 0 && fileIV == 0) const_cast(this)->initHeader(); diff --git a/fs/Context.cpp b/fs/Context.cpp index 44691f0..d7e1c3a 100644 --- a/fs/Context.cpp +++ b/fs/Context.cpp @@ -27,7 +27,7 @@ namespace encfs { -EncFS_Context::EncFS_Context() { +EncFS_Context::EncFS_Context() : publicFilesystem(false), running(false) { #ifdef CMAKE_USE_PTHREADS_INIT pthread_cond_init(&wakeupCond, 0); #endif @@ -72,7 +72,7 @@ void EncFS_Context::setRoot(const shared_ptr &r) { if (r) rootCipherDir = r->rootDirectory(); } -bool EncFS_Context::isMounted() { return root; } +bool EncFS_Context::isMounted() const { return root; } int EncFS_Context::getAndResetUsageCounter() { Lock lock(contextMutex); @@ -114,7 +114,7 @@ void EncFS_Context::renameNode(const char *from, const char *to) { } shared_ptr EncFS_Context::getNode(void *pl) { - Placeholder *ph = (Placeholder *)pl; + Placeholder *ph = static_cast(pl); return ph->node; } @@ -130,7 +130,7 @@ void *EncFS_Context::putNode(const char *path, void EncFS_Context::eraseNode(const char *path, void *pl) { Lock lock(contextMutex); - Placeholder *ph = (Placeholder *)pl; + Placeholder *ph = static_cast(pl); FileMap::iterator it = openFiles.find(std::string(path)); rAssert(it != openFiles.end()); diff --git a/fs/Context.h b/fs/Context.h index 92ca0cc..9b3c23f 100644 --- a/fs/Context.h +++ b/fs/Context.h @@ -48,7 +48,7 @@ class EncFS_Context { EncFS_Context(); ~EncFS_Context(); - shared_ptr getNode(void *ptr); + static shared_ptr getNode(void *ptr); shared_ptr lookupNode(const char *path); int getAndResetUsageCounter(); @@ -62,7 +62,7 @@ class EncFS_Context { void setRoot(const shared_ptr &root); shared_ptr getRoot(int *err); - bool isMounted(); + bool isMounted() const; shared_ptr args; shared_ptr opts; diff --git a/fs/DirNode.cpp b/fs/DirNode.cpp index 57843aa..9ffcdc2 100644 --- a/fs/DirNode.cpp +++ b/fs/DirNode.cpp @@ -50,7 +50,7 @@ namespace encfs { class DirDeleter { public: - void operator()(DIR *d) { ::closedir(d); } + void operator()(DIR *d) const { ::closedir(d); } }; DirTraverse::DirTraverse(const shared_ptr &_dirPtr, uint64_t _iv, @@ -268,7 +268,7 @@ bool DirNode::hasDirectoryNameDependency() const { return naming ? naming->getChainedNameIV() : false; } -string DirNode::rootDirectory() { +string DirNode::rootDirectory() const { // don't update last access here, otherwise 'du' would cause lastAccess to // be reset. // chop off '/' terminator from root dir. diff --git a/fs/DirNode.h b/fs/DirNode.h index 0e96c45..6cceb83 100644 --- a/fs/DirNode.h +++ b/fs/DirNode.h @@ -84,7 +84,7 @@ class DirNode { ~DirNode(); // return the path to the root directory - std::string rootDirectory(); + std::string rootDirectory() const; // find files shared_ptr lookupNode(const char *plaintextName, diff --git a/fs/FileNode.cpp b/fs/FileNode.cpp index 8ec379d..b4188f3 100644 --- a/fs/FileNode.cpp +++ b/fs/FileNode.cpp @@ -237,7 +237,7 @@ int FileNode::sync(bool datasync) { int fh = io->open(O_RDONLY); if (fh >= 0) { - int res = -EIO; + int res; #ifdef linux if (datasync) res = fdatasync(fh); diff --git a/fs/MemFileIO.cpp b/fs/MemFileIO.cpp index 6910db3..493ab67 100644 --- a/fs/MemFileIO.cpp +++ b/fs/MemFileIO.cpp @@ -29,11 +29,6 @@ namespace encfs { static Interface MemFileIO_iface = makeInterface("FileIO/Mem", 1, 0, 0); -MemFileIO* NewMemFileIO(const Interface& iface) { - (void)iface; - return new MemFileIO(0); -} - MemFileIO::MemFileIO(int size) : writable(false) { buf.resize(size); } MemFileIO::~MemFileIO() {} diff --git a/fs/RawFileIO.cpp b/fs/RawFileIO.cpp index d4d129e..c01657f 100644 --- a/fs/RawFileIO.cpp +++ b/fs/RawFileIO.cpp @@ -39,11 +39,6 @@ namespace encfs { static Interface RawFileIO_iface = makeInterface("FileIO/Raw", 1, 0, 0); -FileIO *NewRawFileIO(const Interface &iface) { - (void)iface; - return new RawFileIO(); -} - inline void swap(int &x, int &y) { int tmp = x; x = y; diff --git a/fs/encfs.cpp b/fs/encfs.cpp index bfaaacc..b97fe9c 100644 --- a/fs/encfs.cpp +++ b/fs/encfs.cpp @@ -79,7 +79,7 @@ namespace encfs { #define GET_FN(ctx, finfo) ctx->getNode((void *)(uintptr_t)finfo->fh) static EncFS_Context *context() { - return (EncFS_Context *)fuse_get_context()->private_data; + return static_cast(fuse_get_context()->private_data); } /*