Return Q_NULLPTR instead of 0 when the return type is a pointer.

This commit is contained in:
Felix Geyer 2012-07-23 14:58:57 +02:00
parent fcc936ceff
commit ecea101962
12 changed files with 67 additions and 66 deletions

View File

@ -104,7 +104,7 @@ Entry* Database::recFindEntry(const Uuid& uuid, Group* group)
}
}
return 0;
return Q_NULLPTR;
}
Group* Database::resolveGroup(const Uuid& uuid)
@ -125,7 +125,7 @@ Group* Database::recFindGroup(const Uuid& uuid, Group* group)
}
}
return 0;
return Q_NULLPTR;
}
QList<DeletedObject> Database::deletedObjects()

View File

@ -589,7 +589,7 @@ const Database* Entry::database() const
return m_group->database();
}
else {
return 0;
return Q_NULLPTR;
}
}

View File

@ -46,7 +46,7 @@ SymmetricCipherBackend* SymmetricCipher::createBackend(SymmetricCipher::Algorith
default:
Q_ASSERT(false);
return 0;
return Q_NULLPTR;
}
}

View File

@ -21,6 +21,7 @@
#include <QtCore/QByteArray>
#include <QtCore/QScopedPointer>
#include "core/Global.h"
#include "crypto/SymmetricCipherBackend.h"
class SymmetricCipher

View File

@ -63,14 +63,14 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor
keyfileData = readKeyfile(keyfileDevice);
if (keyfileData.isEmpty()) {
return 0;
return Q_NULLPTR;
}
if (!keyfileDevice->seek(0)) {
return 0;
return Q_NULLPTR;
}
if (!newFileKey.load(keyfileDevice)) {
return 0;
return Q_NULLPTR;
}
}
@ -87,68 +87,68 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor
quint32 signature1 = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok);
if (!ok || signature1 != 0x9AA2D903) {
raiseError(tr("Not a KeePass database."));
return 0;
return Q_NULLPTR;
}
quint32 signature2 = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok);
if (!ok || signature2 != 0xB54BFB65) {
raiseError(tr("Not a KeePass database."));
return 0;
return Q_NULLPTR;
}
m_encryptionFlags = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok);
if (!ok || !(m_encryptionFlags & KeePass1::Rijndael || m_encryptionFlags & KeePass1::Twofish)) {
raiseError(tr("Unsupported encryption algorithm."));
return 0;
return Q_NULLPTR;
}
quint32 version = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok);
if (!ok || (version & KeePass1::FILE_VERSION_CRITICAL_MASK)
!= (KeePass1::FILE_VERSION & KeePass1::FILE_VERSION_CRITICAL_MASK)) {
raiseError(tr("Unsupported KeePass database version."));
return 0;
return Q_NULLPTR;
}
m_masterSeed = m_device->read(16);
if (m_masterSeed.size() != 16) {
// TODO: error
return 0;
return Q_NULLPTR;
}
m_encryptionIV = m_device->read(16);
if (m_encryptionIV.size() != 16) {
// TODO: error
return 0;
return Q_NULLPTR;
}
quint32 numGroups = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok);
if (!ok) {
// TODO: error
return 0;
return Q_NULLPTR;
}
quint32 numEntries = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok);
if (!ok) {
// TODO: error
return 0;
return Q_NULLPTR;
}
m_contentHashHeader = m_device->read(32);
if (m_contentHashHeader.size() != 32) {
// TODO: error
return 0;
return Q_NULLPTR;
}
m_transformSeed = m_device->read(32);
if (m_transformSeed.size() != 32) {
// TODO: error
return 0;
return Q_NULLPTR;
}
m_transformRounds = Endian::readUInt32(m_device, KeePass1::BYTEORDER, &ok);
if (!ok) {
// TODO: error
return 0;
return Q_NULLPTR;
}
m_db->setTransformRounds(m_transformRounds);
@ -158,14 +158,14 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor
if (!cipherStream) {
// TODO: error
return 0;
return Q_NULLPTR;
}
QList<Group*> groups;
for (quint32 i = 0; i < numGroups; i++) {
Group* group = readGroup(cipherStream.data());
if (!group) {
return 0;
return Q_NULLPTR;
}
groups.append(group);
}
@ -174,13 +174,13 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor
for (quint32 i = 0; i < numEntries; i++) {
Entry* entry = readEntry(cipherStream.data());
if (!entry) {
return 0;
return Q_NULLPTR;
}
entries.append(entry);
}
if (!constructGroupTree(groups)) {
return 0;
return Q_NULLPTR;
}
Q_FOREACH (Entry* entry, entries) {
@ -192,7 +192,7 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor
else {
quint32 groupId = m_entryGroupIds.value(entry);
if (!m_groupIds.contains(groupId)) {
return 0;
return Q_NULLPTR;
}
entry->setGroup(m_groupIds.value(groupId));
entry->setUuid(Uuid::random());
@ -244,7 +244,7 @@ Database* KeePass1Reader::readDatabase(QIODevice* device, const QString& passwor
keyFile.reset(new QFile(keyfileName));
if (!keyFile->open(QFile::ReadOnly)) {
raiseError(keyFile->errorString());
return 0;
return Q_NULLPTR;
}
}
@ -259,14 +259,14 @@ Database* KeePass1Reader::readDatabase(const QString& filename, const QString& p
QFile dbFile(filename);
if (!dbFile.open(QFile::ReadOnly)) {
raiseError(dbFile.errorString());
return 0;
return Q_NULLPTR;
}
Database* db = readDatabase(&dbFile, password, keyfileName);
if (dbFile.error() != QFile::NoError) {
raiseError(dbFile.errorString());
return 0;
return Q_NULLPTR;
}
return db;
@ -340,7 +340,7 @@ SymmetricCipherStream* KeePass1Reader::testKeys(const QString& password, const Q
cipherStream->close();
if (!m_device->seek(contentPos)) {
// TODO: error
return 0;
return Q_NULLPTR;
}
cipherStream->open(QIODevice::ReadOnly);
@ -398,18 +398,18 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream)
do {
quint16 fieldType = Endian::readUInt16(cipherStream, KeePass1::BYTEORDER, &ok);
if (!ok) {
return 0;
return Q_NULLPTR;
}
int fieldSize = static_cast<int>(Endian::readUInt32(cipherStream, KeePass1::BYTEORDER, &ok));
if (!ok) {
return 0;
return Q_NULLPTR;
}
QByteArray fieldData = cipherStream->read(fieldSize);
if (fieldData.size() != fieldSize) {
// TODO: error
return 0;
return Q_NULLPTR;
}
switch (fieldType) {
@ -418,7 +418,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream)
break;
case 0x0001:
if (fieldSize != 4) {
return 0;
return Q_NULLPTR;
}
groupId = Endian::bytesToUInt32(fieldData, KeePass1::BYTEORDER);
break;
@ -428,7 +428,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream)
case 0x0003:
{
if (fieldSize != 5) {
return 0;
return Q_NULLPTR;
}
QDateTime dateTime = dateFromPackedStruct(fieldData);
if (dateTime.isValid()) {
@ -439,7 +439,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream)
case 0x0004:
{
if (fieldSize != 5) {
return 0;
return Q_NULLPTR;
}
QDateTime dateTime = dateFromPackedStruct(fieldData);
if (dateTime.isValid()) {
@ -450,7 +450,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream)
case 0x0005:
{
if (fieldSize != 5) {
return 0;
return Q_NULLPTR;
}
QDateTime dateTime = dateFromPackedStruct(fieldData);
if (dateTime.isValid()) {
@ -461,7 +461,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream)
case 0x0006:
{
if (fieldSize != 5) {
return 0;
return Q_NULLPTR;
}
QDateTime dateTime = dateFromPackedStruct(fieldData);
if (dateTime.isValid()) {
@ -473,7 +473,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream)
case 0x0007:
{
if (fieldSize != 4) {
return 0;
return Q_NULLPTR;
}
quint32 iconNumber = Endian::bytesToUInt32(fieldData, KeePass1::BYTEORDER);
group->setIcon(iconNumber);
@ -482,7 +482,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream)
case 0x0008:
{
if (fieldSize != 2) {
return 0;
return Q_NULLPTR;
}
groupLevel = Endian::bytesToUInt16(fieldData, KeePass1::BYTEORDER);
break;
@ -495,7 +495,7 @@ Group* KeePass1Reader::readGroup(QIODevice* cipherStream)
break;
default:
// invalid field
return 0;
return Q_NULLPTR;
}
} while (!reachedEnd);
@ -521,18 +521,18 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream)
do {
quint16 fieldType = Endian::readUInt16(cipherStream, KeePass1::BYTEORDER, &ok);
if (!ok) {
return 0;
return Q_NULLPTR;
}
int fieldSize = static_cast<int>(Endian::readUInt32(cipherStream, KeePass1::BYTEORDER, &ok));
if (!ok) {
return 0;
return Q_NULLPTR;
}
QByteArray fieldData = cipherStream->read(fieldSize);
if (fieldData.size() != fieldSize) {
// TODO: error
return 0;
return Q_NULLPTR;
}
switch (fieldType) {
@ -541,14 +541,14 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream)
break;
case 0x0001:
if (fieldSize != 16) {
return 0;
return Q_NULLPTR;
}
m_entryUuids.insert(fieldData, entry.data());
break;
case 0x0002:
{
if (fieldSize != 4) {
return 0;
return Q_NULLPTR;
}
quint32 groupId = Endian::bytesToUInt32(fieldData, KeePass1::BYTEORDER);
m_entryGroupIds.insert(entry.data(), groupId);
@ -557,7 +557,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream)
case 0x0003:
{
if (fieldSize != 4) {
return 0;
return Q_NULLPTR;
}
quint32 iconNumber = Endian::bytesToUInt32(fieldData, KeePass1::BYTEORDER);
entry->setIcon(iconNumber);
@ -581,7 +581,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream)
case 0x0009:
{
if (fieldSize != 5) {
return 0;
return Q_NULLPTR;
}
QDateTime dateTime = dateFromPackedStruct(fieldData);
if (dateTime.isValid()) {
@ -592,7 +592,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream)
case 0x000A:
{
if (fieldSize != 5) {
return 0;
return Q_NULLPTR;
}
QDateTime dateTime = dateFromPackedStruct(fieldData);
if (dateTime.isValid()) {
@ -603,7 +603,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream)
case 0x000B:
{
if (fieldSize != 5) {
return 0;
return Q_NULLPTR;
}
QDateTime dateTime = dateFromPackedStruct(fieldData);
if (dateTime.isValid()) {
@ -614,7 +614,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream)
case 0x000C:
{
if (fieldSize != 5) {
return 0;
return Q_NULLPTR;
}
QDateTime dateTime = dateFromPackedStruct(fieldData);
if (dateTime.isValid()) {
@ -636,7 +636,7 @@ Entry* KeePass1Reader::readEntry(QIODevice* cipherStream)
break;
default:
// invalid field
return 0;
return Q_NULLPTR;
}
} while (!reachedEnd);

View File

@ -50,20 +50,20 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke
quint32 signature1 = Endian::readUInt32(m_device, KeePass2::BYTEORDER, &ok);
if (!ok || signature1 != KeePass2::SIGNATURE_1) {
raiseError(tr("Not a KeePass database."));
return 0;
return Q_NULLPTR;
}
quint32 signature2 = Endian::readUInt32(m_device, KeePass2::BYTEORDER, &ok);
if (!ok || signature2 != KeePass2::SIGNATURE_2) {
raiseError(tr("Not a KeePass database."));
return 0;
return Q_NULLPTR;
}
quint32 version = Endian::readUInt32(m_device, KeePass2::BYTEORDER, &ok) & KeePass2::FILE_VERSION_CRITICAL_MASK;
quint32 maxVersion = KeePass2::FILE_VERSION & KeePass2::FILE_VERSION_CRITICAL_MASK;
if (!ok || (version < KeePass2::FILE_VERSION_MIN) || (version > maxVersion)) {
raiseError(tr("Unsupported KeePass database version."));
return 0;
return Q_NULLPTR;
}
while (readHeaderField() && !hasError()) {
@ -86,7 +86,7 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke
if (realStart != m_streamStartBytes) {
raiseError(tr("Wrong key or database file is corrupt."));
return 0;
return Q_NULLPTR;
}
HashedBlockStream hashedStream(&cipherStream);
@ -121,7 +121,7 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke
if (xmlReader.hasError()) {
raiseError(xmlReader.errorString());
return 0;
return Q_NULLPTR;
}
return db.take();
@ -132,14 +132,14 @@ Database* KeePass2Reader::readDatabase(const QString& filename, const CompositeK
QFile file(filename);
if (!file.open(QFile::ReadOnly)) {
raiseError(file.errorString());
return 0;
return Q_NULLPTR;
}
QScopedPointer<Database> db(readDatabase(&file, key));
if (file.error() != QFile::NoError) {
raiseError(file.errorString());
return 0;
return Q_NULLPTR;
}
return db.take();

View File

@ -895,7 +895,7 @@ QByteArray KeePass2XmlReader::readCompressedBinary()
Group* KeePass2XmlReader::getGroup(const Uuid& uuid)
{
if (uuid.isNull()) {
return 0;
return Q_NULLPTR;
}
if (m_groups.contains(uuid)) {
@ -914,7 +914,7 @@ Group* KeePass2XmlReader::getGroup(const Uuid& uuid)
Entry* KeePass2XmlReader::getEntry(const Uuid& uuid)
{
if (uuid.isNull()) {
return 0;
return Q_NULLPTR;
}
if (m_entries.contains(uuid)) {

View File

@ -486,7 +486,7 @@ Database* DatabaseTabWidget::indexDatabase(int index)
}
}
return 0;
return Q_NULLPTR;
}
DatabaseManagerStruct DatabaseTabWidget::indexDatabaseManagerStruct(int index)
@ -514,7 +514,7 @@ Database* DatabaseTabWidget::databaseFromDatabaseWidget(DatabaseWidget* dbWidget
}
}
return 0;
return Q_NULLPTR;
}
void DatabaseTabWidget::insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct)
@ -542,7 +542,7 @@ DatabaseWidget* DatabaseTabWidget::currentDatabaseWidget()
return m_dbList[db].dbWidget;
}
else {
return 0;
return Q_NULLPTR;
}
}

View File

@ -204,7 +204,7 @@ QStringList EntryModel::mimeTypes() const
QMimeData* EntryModel::mimeData(const QModelIndexList& indexes) const
{
if (indexes.isEmpty()) {
return 0;
return Q_NULLPTR;
}
QMimeData* data = new QMimeData();

View File

@ -81,7 +81,7 @@ Entry* EntryView::currentEntry()
return m_model->entryFromIndex(m_sortModel->mapToSource(list.first()));
}
else {
return 0;
return Q_NULLPTR;
}
}
@ -101,7 +101,7 @@ Entry* EntryView::entryFromIndex(const QModelIndex& index)
return m_model->entryFromIndex(m_sortModel->mapToSource(index));
}
else {
return 0;
return Q_NULLPTR;
}
}

View File

@ -273,7 +273,7 @@ QStringList GroupModel::mimeTypes() const
QMimeData* GroupModel::mimeData(const QModelIndexList& indexes) const
{
if (indexes.isEmpty()) {
return 0;
return Q_NULLPTR;
}
QMimeData* data = new QMimeData();

View File

@ -66,7 +66,7 @@ void GroupView::dragMoveEvent(QDragMoveEvent* event)
Group* GroupView::currentGroup()
{
if (currentIndex() == QModelIndex()) {
return 0;
return Q_NULLPTR;
}
else {
return m_model->groupFromIndex(currentIndex());