mirror of
https://github.com/vgough/encfs.git
synced 2024-11-21 23:43:26 +01:00
cleanup warnings from cppcheck
git-svn-id: http://encfs.googlecode.com/svn/trunk@124 db9cf616-1c43-0410-9cb8-a902689de0d6
This commit is contained in:
parent
d1a9ccdd19
commit
b606ef122b
@ -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<string, ConfigVar>::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<string, ConfigVar>::const_iterator it = vars.find(varName);
|
||||
|
@ -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;
|
||||
|
@ -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(); }
|
||||
|
@ -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;
|
||||
|
@ -231,7 +231,7 @@ shared_ptr<CipherV1> 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<byte> buf(encodedSize);
|
||||
|
@ -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;
|
||||
|
@ -121,7 +121,7 @@ class BotanBlockCipher : public BlockCipher {
|
||||
shared_ptr<Pipe> decryptor;
|
||||
|
||||
public:
|
||||
BotanBlockCipher() {}
|
||||
BotanBlockCipher() : encryption(nullptr), decryption(nullptr) {}
|
||||
virtual ~BotanBlockCipher() {}
|
||||
|
||||
bool rekey(const CipherKey& key, const string& cipherMode) {
|
||||
|
@ -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;
|
||||
|
@ -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<EncFS_Context *>(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<EncFS_Context *>(_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<EncFS_Context *>(_arg);
|
||||
shared_ptr<EncFS_Args> arg = ctx->args;
|
||||
|
||||
const int timeoutCycles = 60 * arg->idleTimeout / ActivityCheckInterval;
|
||||
|
@ -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
|
||||
|
@ -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<CipherFileIO *>(this)->initHeader();
|
||||
|
||||
|
@ -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<DirNode> &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<FileNode> EncFS_Context::getNode(void *pl) {
|
||||
Placeholder *ph = (Placeholder *)pl;
|
||||
Placeholder *ph = static_cast<Placeholder *>(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<Placeholder *>(pl);
|
||||
|
||||
FileMap::iterator it = openFiles.find(std::string(path));
|
||||
rAssert(it != openFiles.end());
|
||||
|
@ -48,7 +48,7 @@ class EncFS_Context {
|
||||
EncFS_Context();
|
||||
~EncFS_Context();
|
||||
|
||||
shared_ptr<FileNode> getNode(void *ptr);
|
||||
static shared_ptr<FileNode> getNode(void *ptr);
|
||||
shared_ptr<FileNode> lookupNode(const char *path);
|
||||
|
||||
int getAndResetUsageCounter();
|
||||
@ -62,7 +62,7 @@ class EncFS_Context {
|
||||
|
||||
void setRoot(const shared_ptr<DirNode> &root);
|
||||
shared_ptr<DirNode> getRoot(int *err);
|
||||
bool isMounted();
|
||||
bool isMounted() const;
|
||||
|
||||
shared_ptr<EncFS_Args> args;
|
||||
shared_ptr<EncFS_Opts> opts;
|
||||
|
@ -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<DIR> &_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.
|
||||
|
@ -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<FileNode> lookupNode(const char *plaintextName,
|
||||
|
@ -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);
|
||||
|
@ -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() {}
|
||||
|
@ -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;
|
||||
|
@ -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<EncFS_Context *>(fuse_get_context()->private_data);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user