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) { void EncFS_Context::getAndResetUsageCounter(int *usage, int *openCount) {
Lock lock(contextMutex); Lock lock(contextMutex);

View File

@ -149,7 +149,7 @@ class RenameOp {
~RenameOp(); ~RenameOp();
operator bool() const { return renameList.get() != nullptr; } operator bool() const { return renameList != nullptr; }
bool apply(); bool apply();
void undo(); void undo();
@ -659,7 +659,6 @@ std::shared_ptr<FileNode> DirNode::findOrCreate(const char *plainName) {
// See if we already have a FileNode for this path. // See if we already have a FileNode for this path.
if (ctx != nullptr) { if (ctx != nullptr) {
node = ctx->lookupNode(plainName); node = ctx->lookupNode(plainName);
}
// If we don't, create a new one. // If we don't, create a new one.
if (!node) { if (!node) {
@ -675,6 +674,7 @@ std::shared_ptr<FileNode> DirNode::findOrCreate(const char *plainName) {
VLOG(1) << "created FileNode for " << node->cipherName(); VLOG(1) << "created FileNode for " << node->cipherName();
} }
}
return node; return node;
} }

View File

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

View File

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