More careful null checking and member initalization.

This commit is contained in:
Felix Geyer 2014-03-22 12:07:06 +01:00
parent 54bb7462f6
commit b9370c6e79
12 changed files with 32 additions and 26 deletions

View File

@ -40,6 +40,7 @@ AutoType::AutoType(QObject* parent, bool test)
, m_pluginLoader(new QPluginLoader(this)) , m_pluginLoader(new QPluginLoader(this))
, m_plugin(Q_NULLPTR) , m_plugin(Q_NULLPTR)
, m_executor(Q_NULLPTR) , m_executor(Q_NULLPTR)
, m_windowFromGlobal(0)
{ {
// prevent crash when the plugin has unresolved symbols // prevent crash when the plugin has unresolved symbols
m_pluginLoader->setLoadHints(QLibrary::ResolveAllSymbolsHint); m_pluginLoader->setLoadHints(QLibrary::ResolveAllSymbolsHint);

View File

@ -30,6 +30,7 @@ Entry::Entry()
, m_attachments(new EntryAttachments(this)) , m_attachments(new EntryAttachments(this))
, m_autoTypeAssociations(new AutoTypeAssociations(this)) , m_autoTypeAssociations(new AutoTypeAssociations(this))
, m_tmpHistoryItem(Q_NULLPTR) , m_tmpHistoryItem(Q_NULLPTR)
, m_modifiedSinceBegin(false)
, m_updateTimeinfo(true) , m_updateTimeinfo(true)
{ {
m_data.iconNumber = DefaultIconNumber; m_data.iconNumber = DefaultIconNumber;

View File

@ -25,7 +25,6 @@ SymmetricCipher::SymmetricCipher(SymmetricCipher::Algorithm algo, SymmetricCiphe
SymmetricCipher::Direction direction, const QByteArray& key, const QByteArray& iv) SymmetricCipher::Direction direction, const QByteArray& key, const QByteArray& iv)
: m_backend(createBackend(algo, mode, direction)) : m_backend(createBackend(algo, mode, direction))
{ {
m_backend->init();
m_backend->setKey(key); m_backend->setKey(key);
m_backend->setIv(iv); m_backend->setIv(iv);
} }

View File

@ -24,7 +24,6 @@ class SymmetricCipherBackend
{ {
public: public:
virtual ~SymmetricCipherBackend() {} virtual ~SymmetricCipherBackend() {}
virtual void init() = 0;
virtual void setKey(const QByteArray& key) = 0; virtual void setKey(const QByteArray& key) = 0;
virtual void setIv(const QByteArray& iv) = 0; virtual void setIv(const QByteArray& iv) = 0;

View File

@ -28,6 +28,16 @@ SymmetricCipherGcrypt::SymmetricCipherGcrypt(SymmetricCipher::Algorithm algo, Sy
, m_blockSize(-1) , m_blockSize(-1)
{ {
Q_ASSERT(Crypto::initalized()); Q_ASSERT(Crypto::initalized());
gcry_error_t error;
error = gcry_cipher_open(&m_ctx, m_algo, m_mode, 0);
Q_ASSERT(error == 0); // TODO: real error checking
size_t blockSizeT;
error = gcry_cipher_algo_info(m_algo, GCRYCTL_GET_BLKLEN, Q_NULLPTR, &blockSizeT);
Q_ASSERT(error == 0);
m_blockSize = blockSizeT;
} }
SymmetricCipherGcrypt::~SymmetricCipherGcrypt() SymmetricCipherGcrypt::~SymmetricCipherGcrypt()
@ -73,19 +83,6 @@ int SymmetricCipherGcrypt::gcryptMode(SymmetricCipher::Mode mode)
} }
} }
void SymmetricCipherGcrypt::init()
{
gcry_error_t error;
error = gcry_cipher_open(&m_ctx, m_algo, m_mode, 0);
Q_ASSERT(error == 0); // TODO: real error checking
size_t blockSizeT;
error = gcry_cipher_algo_info(m_algo, GCRYCTL_GET_BLKLEN, Q_NULLPTR, &blockSizeT);
Q_ASSERT(error == 0);
m_blockSize = blockSizeT;
}
void SymmetricCipherGcrypt::setKey(const QByteArray& key) void SymmetricCipherGcrypt::setKey(const QByteArray& key)
{ {
m_key = key; m_key = key;

View File

@ -29,7 +29,6 @@ public:
SymmetricCipherGcrypt(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode, SymmetricCipherGcrypt(SymmetricCipher::Algorithm algo, SymmetricCipher::Mode mode,
SymmetricCipher::Direction direction); SymmetricCipher::Direction direction);
~SymmetricCipherGcrypt(); ~SymmetricCipherGcrypt();
void init();
void setKey(const QByteArray& key); void setKey(const QByteArray& key);
void setIv(const QByteArray& iv); void setIv(const QByteArray& iv);

View File

@ -33,10 +33,6 @@ SymmetricCipherSalsa20::~SymmetricCipherSalsa20()
{ {
} }
void SymmetricCipherSalsa20::init()
{
}
void SymmetricCipherSalsa20::setKey(const QByteArray& key) void SymmetricCipherSalsa20::setKey(const QByteArray& key)
{ {
Q_ASSERT((key.size() == 16) || (key.size() == 32)); Q_ASSERT((key.size() == 16) || (key.size() == 32));

View File

@ -31,7 +31,6 @@ public:
void setAlgorithm(SymmetricCipher::Algorithm algo); void setAlgorithm(SymmetricCipher::Algorithm algo);
void setMode(SymmetricCipher::Mode mode); void setMode(SymmetricCipher::Mode mode);
void setDirection(SymmetricCipher::Direction direction); void setDirection(SymmetricCipher::Direction direction);
void init();
void setKey(const QByteArray& key); void setKey(const QByteArray& key);
void setIv(const QByteArray& iv); void setIv(const QByteArray& iv);

View File

@ -591,12 +591,24 @@ void DatabaseWidget::entryActivationSignalReceived(Entry* entry, EntryModel::Mod
void DatabaseWidget::switchToEntryEdit() void DatabaseWidget::switchToEntryEdit()
{ {
switchToEntryEdit(m_entryView->currentEntry(), false); Entry* entry = m_entryView->currentEntry();
Q_ASSERT(entry);
if (!entry) {
return;
}
switchToEntryEdit(entry, false);
} }
void DatabaseWidget::switchToGroupEdit() void DatabaseWidget::switchToGroupEdit()
{ {
switchToGroupEdit(m_groupView->currentGroup(), false); Group* group = m_groupView->currentGroup();
Q_ASSERT(group);
if (!group) {
return;
}
switchToGroupEdit(group, false);
} }
void DatabaseWidget::switchToMasterKeyChange() void DatabaseWidget::switchToMasterKeyChange()

View File

@ -35,6 +35,7 @@ IconStruct::IconStruct()
EditWidgetIcons::EditWidgetIcons(QWidget* parent) EditWidgetIcons::EditWidgetIcons(QWidget* parent)
: QWidget(parent) : QWidget(parent)
, m_ui(new Ui::EditWidgetIcons()) , m_ui(new Ui::EditWidgetIcons())
, m_database(Q_NULLPTR)
, m_defaultIconModel(new DefaultIconModel(this)) , m_defaultIconModel(new DefaultIconModel(this))
, m_customIconModel(new CustomIconModel(this)) , m_customIconModel(new CustomIconModel(this))
{ {

View File

@ -226,7 +226,9 @@ void MainWindow::updateCopyAttributesMenu()
if (!dbWidget) { if (!dbWidget) {
return; return;
} }
if (!dbWidget->entryView()->isSingleEntrySelected()) {
Entry* entry = dbWidget->entryView()->currentEntry();
if (!entry || !dbWidget->entryView()->isSingleEntrySelected()) {
return; return;
} }
@ -235,8 +237,6 @@ void MainWindow::updateCopyAttributesMenu()
delete actions[i]; delete actions[i];
} }
Entry* entry = dbWidget->entryView()->currentEntry();
Q_FOREACH (const QString& key, entry->attributes()->customKeys()) { Q_FOREACH (const QString& key, entry->attributes()->customKeys()) {
QAction* action = m_ui->menuEntryCopyAttribute->addAction(key); QAction* action = m_ui->menuEntryCopyAttribute->addAction(key);
m_copyAdditionalAttributeActions->addAction(action); m_copyAdditionalAttributeActions->addAction(action);

View File

@ -28,6 +28,8 @@ SettingsWidget::SettingsWidget(QWidget* parent)
, m_generalWidget(new QWidget()) , m_generalWidget(new QWidget())
, m_secUi(new Ui::SettingsWidgetSecurity()) , m_secUi(new Ui::SettingsWidgetSecurity())
, m_generalUi(new Ui::SettingsWidgetGeneral()) , m_generalUi(new Ui::SettingsWidgetGeneral())
, m_globalAutoTypeKey(static_cast<Qt::Key>(0))
, m_globalAutoTypeModifiers(Qt::NoModifier)
{ {
setHeadline(tr("Application Settings")); setHeadline(tr("Application Settings"));