lint: misc cleanup, including possible NPE

This commit is contained in:
Valient Gough 2017-08-03 23:26:12 -07:00
parent d7852e6f56
commit c947c684c7
No known key found for this signature in database
GPG Key ID: 33C65E29813C14DF
4 changed files with 22 additions and 33 deletions

View File

@ -75,7 +75,7 @@ void EncFS_Context::setRoot(const std::shared_ptr<DirNode> &r) {
}
}
bool EncFS_Context::isMounted() { return root.get() != nullptr; }
bool EncFS_Context::isMounted() { return root != nullptr; }
void EncFS_Context::getAndResetUsageCounter(int *usage, int *openCount) {
Lock lock(contextMutex);

View File

@ -149,7 +149,7 @@ class RenameOp {
~RenameOp();
operator bool() const { return renameList.get() != nullptr; }
operator bool() const { return renameList != nullptr; }
bool apply();
void undo();
@ -659,21 +659,21 @@ std::shared_ptr<FileNode> DirNode::findOrCreate(const char *plainName) {
// See if we already have a FileNode for this path.
if (ctx != nullptr) {
node = ctx->lookupNode(plainName);
}
// If we don't, create a new one.
if (!node) {
uint64_t iv = 0;
string cipherName = naming->encodePath(plainName, &iv);
uint64_t fuseFh = ctx->nextFuseFh();
node.reset(new FileNode(this, fsConfig, plainName,
(rootDir + cipherName).c_str(), fuseFh));
// If we don't, create a new one.
if (!node) {
uint64_t iv = 0;
string cipherName = naming->encodePath(plainName, &iv);
uint64_t fuseFh = ctx->nextFuseFh();
node.reset(new FileNode(this, fsConfig, plainName,
(rootDir + cipherName).c_str(), fuseFh));
if (fsConfig->config->externalIVChaining) {
node->setName(nullptr, nullptr, iv);
if (fsConfig->config->externalIVChaining) {
node->setName(nullptr, nullptr, iv);
}
VLOG(1) << "created FileNode for " << node->cipherName();
}
VLOG(1) << "created FileNode for " << node->cipherName();
}
return node;

View File

@ -125,11 +125,7 @@ EncFS_Root::~EncFS_Root() = default;
bool fileExists(const char *fileName) {
struct stat buf;
if (lstat(fileName, &buf) == 0) {
return true;
}
// XXX show perror?
return false;
return lstat(fileName, &buf) == 0;
}
bool isDirectory(const char *fileName) {
@ -141,10 +137,7 @@ bool isDirectory(const char *fileName) {
}
bool isAbsolutePath(const char *fileName) {
if ((fileName != nullptr) && fileName[0] != '\0' && fileName[0] == '/') {
return true;
}
return false;
return (fileName != nullptr) && fileName[0] != '\0' && fileName[0] == '/';
}
const char *lastPathElement(const char *name) {
@ -1306,7 +1299,7 @@ void showFSInfo(const EncFSConfig *config) {
cout << "\n";
}
}
if (config->kdfIterations > 0 && config->salt.size() > 0) {
if (config->kdfIterations > 0 && !config->salt.empty()) {
cout << autosprintf(_("Using PBKDF2, with %i iterations"),
config->kdfIterations)
<< "\n";
@ -1389,12 +1382,12 @@ CipherKey EncFSConfig::makeKey(const char *password, int passwdLen) {
// if no salt is set and we're creating a new password for a new
// FS type, then initialize salt..
if (salt.size() == 0 && kdfIterations == 0 && cfgType >= Config_V6) {
if (salt.empty() && kdfIterations == 0 && cfgType >= Config_V6) {
// upgrade to using salt
salt.resize(20);
}
if (salt.size() > 0) {
if (!salt.empty()) {
// if iterations isn't known, then we're creating a new key, so
// randomize the salt..
if (kdfIterations == 0 &&

View File

@ -414,9 +414,8 @@ CipherKey SSL_Cipher::newKey(const char *password, int passwdLength) {
}
} else {
// for backward compatibility with filesystems created with 1:0
bytes = EVP_BytesToKey(_blockCipher, EVP_sha1(), nullptr,
(unsigned char *)password, passwdLength, 16,
KeyData(key), IVData(key));
EVP_BytesToKey(_blockCipher, EVP_sha1(), nullptr, (unsigned char *)password,
passwdLength, 16, KeyData(key), IVData(key));
}
initKey(key, _blockCipher, _streamCipher, _keySize);
@ -610,10 +609,7 @@ bool SSL_Cipher::compareKey(const CipherKey &A, const CipherKey &B) const {
rAssert(key1->keySize == _keySize);
rAssert(key2->keySize == _keySize);
if (memcmp(key1->buffer, key2->buffer, _keySize + _ivLength) != 0) {
return false;
}
return true;
return memcmp(key1->buffer, key2->buffer, _keySize + _ivLength) == 0;
}
int SSL_Cipher::encodedKeySize() const {