clang-tidy: use braced init list (#7998)

This commit is contained in:
Rosen Penev 2023-01-29 07:05:44 -08:00 committed by GitHub
parent 0f7ef275ab
commit 318157d242
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 87 additions and 87 deletions

View File

@ -225,7 +225,7 @@ void AutoType::createTestInstance()
QStringList AutoType::windowTitles()
{
if (!m_plugin) {
return QStringList();
return {};
}
return m_plugin->windowTitles();

View File

@ -38,17 +38,17 @@ public:
static Result Ok()
{
return Result(true, false, QString());
return {true, false, QString()};
}
static Result Retry(const QString& error)
{
return Result(false, true, error);
return {false, true, error};
}
static Result Failed(const QString& error)
{
return Result(false, false, error);
return {false, false, error};
}
bool isOk() const

View File

@ -29,7 +29,7 @@ QString AutoTypePlatformTest::keyToString(Qt::Key key)
QStringList AutoTypePlatformTest::windowTitles()
{
return QStringList();
return {};
}
WId AutoTypePlatformTest::activeWindow()

View File

@ -184,17 +184,17 @@ QString AutoTypePlatformX11::windowTitle(Window window, bool useBlacklist)
if (useBlacklist && !title.isEmpty()) {
if (window == m_rootWindow) {
return QString();
return {};
}
QString className = windowClassName(window);
if (m_classBlacklist.contains(className)) {
return QString();
return {};
}
QList<Window> keepassxWindows = widgetsToX11Windows(QApplication::topLevelWidgets());
if (keepassxWindows.contains(window)) {
return QString();
return {};
}
}

View File

@ -93,7 +93,7 @@ QSharedPointer<PasswordGenerator> Generate::createGenerator(QSharedPointer<QComm
passwordGenerator->setLength(PasswordGenerator::DefaultLength);
} else if (passwordLength.toInt() <= 0) {
err << QObject::tr("Invalid password length %1").arg(passwordLength) << endl;
return QSharedPointer<PasswordGenerator>(nullptr);
return {};
} else {
passwordGenerator->setLength(passwordLength.toInt());
}
@ -139,7 +139,7 @@ QSharedPointer<PasswordGenerator> Generate::createGenerator(QSharedPointer<QComm
if (!passwordGenerator->isValid()) {
err << QObject::tr("Invalid password generator after applying all options") << endl;
return QSharedPointer<PasswordGenerator>(nullptr);
return {};
}
return passwordGenerator;

View File

@ -384,7 +384,7 @@ namespace Utils
if (fieldName == TagsFieldName) {
return entry->tags();
}
return QString("");
return "";
}
QStringList findAttributes(const EntryAttributes& attributes, const QString& name)

View File

@ -50,7 +50,7 @@ QVariant Base32::decode(const QByteArray& encodedData)
}
if (encodedData.size() % 8 != 0) {
return QVariant();
return {};
}
int nPads = 0;
@ -119,7 +119,7 @@ QVariant Base32::decode(const QByteArray& encodedData)
continue;
} else {
// illegal character
return QVariant();
return {};
}
}
}
@ -145,7 +145,7 @@ QVariant Base32::decode(const QByteArray& encodedData)
QByteArray Base32::encode(const QByteArray& data)
{
if (data.size() < 1) {
return QByteArray();
return {};
}
const int nBits = data.size() * 8;

View File

@ -50,12 +50,12 @@ QDateTime Clock::serialized(const QDateTime& dateTime)
QDateTime Clock::datetimeUtc(int year, int month, int day, int hour, int min, int second)
{
return QDateTime(QDate(year, month, day), QTime(hour, min, second), Qt::UTC);
return {QDate(year, month, day), QTime(hour, min, second), Qt::UTC};
}
QDateTime Clock::datetime(int year, int month, int day, int hour, int min, int second)
{
return QDateTime(QDate(year, month, day), QTime(hour, min, second), Qt::LocalTime);
return {QDate(year, month, day), QTime(hour, min, second), Qt::LocalTime};
}
QDateTime Clock::datetimeUtc(qint64 msecSinceEpoch)

View File

@ -1212,7 +1212,7 @@ QString Entry::referenceFieldValue(EntryReferenceType referenceType) const
default:
break;
}
return QString();
return {};
}
void Entry::moveUp()
@ -1329,7 +1329,7 @@ QString Entry::resolvePlaceholder(const QString& placeholder) const
QString Entry::resolveUrlPlaceholder(const QString& str, Entry::PlaceholderType placeholderType) const
{
if (str.isEmpty()) {
return QString();
return {};
}
const QUrl qurl(str);
@ -1360,7 +1360,7 @@ QString Entry::resolveUrlPlaceholder(const QString& str, Entry::PlaceholderType
}
}
return QString();
return {};
}
Entry::PlaceholderType Entry::placeholderType(const QString& placeholder) const
@ -1432,7 +1432,7 @@ QString Entry::resolveUrl(const QString& url) const
}
// No URL in this command
return QString("");
return {};
}
if (!newUrl.isEmpty() && !newUrl.contains("://")) {

View File

@ -166,7 +166,7 @@ QString Group::effectiveAutoTypeSequence() const
const Group* group = this;
do {
if (group->autoTypeEnabled() == Group::Disable) {
return QString();
return {};
}
sequence = group->defaultAutoTypeSequence();

View File

@ -116,7 +116,7 @@ QString PassphraseGenerator::generatePassphrase() const
// In case there was an error loading the wordlist
if (m_wordlist.length() == 0) {
return QString();
return {};
}
QStringList words;

View File

@ -29,22 +29,22 @@ QDateTime operator+(const QDateTime& dateTime, const TimeDelta& delta)
TimeDelta TimeDelta::fromHours(int hours)
{
return TimeDelta(hours, 0, 0, 0);
return {hours, 0, 0, 0};
}
TimeDelta TimeDelta::fromDays(int days)
{
return TimeDelta(0, days, 0, 0);
return {0, days, 0, 0};
}
TimeDelta TimeDelta::fromMonths(int months)
{
return TimeDelta(0, 0, months, 0);
return {0, 0, months, 0};
}
TimeDelta TimeDelta::fromYears(int years)
{
return TimeDelta(0, 0, 0, years);
return {0, 0, 0, years};
}
TimeDelta::TimeDelta()

View File

@ -106,7 +106,7 @@ QByteArray CryptoHash::result() const
} else if (d->hashFunction) {
result = d->hashFunction->final();
}
return QByteArray(reinterpret_cast<const char*>(result.data()), result.size());
return {reinterpret_cast<const char*>(result.data()), int(result.size())};
}
QByteArray CryptoHash::hash(const QByteArray& data, Algorithm algo)

View File

@ -183,7 +183,7 @@ QString KdbxXmlReader::errorString() const
.arg(m_xml.lineNumber())
.arg(m_xml.columnNumber());
}
return QString();
return {};
}
bool KdbxXmlReader::isTrueValue(const QStringRef& value)
@ -1117,13 +1117,13 @@ QUuid KdbxXmlReader::readUuid()
{
QByteArray uuidBin = readBinary();
if (uuidBin.isEmpty()) {
return QUuid();
return {};
}
if (uuidBin.length() != UUID_LENGTH) {
if (m_strictMode) {
raiseError(tr("Invalid uuid value"));
}
return QUuid();
return {};
}
return QUuid::fromRfc4122(uuidBin);
}

View File

@ -391,7 +391,7 @@ QByteArray KeePass1Reader::key(const QByteArray& password, const QByteArray& key
if (!result) {
raiseError(tr("Key transformation failed"));
return QByteArray();
return {};
}
CryptoHash hash(CryptoHash::Sha256);
@ -927,7 +927,7 @@ QDateTime KeePass1Reader::dateFromPackedStruct(const QByteArray& data)
// check for the special "never" datetime
if (dateTime == QDateTime(QDate(2999, 12, 28), QTime(23, 59, 59), Qt::UTC)) {
return QDateTime();
return {};
} else {
return dateTime;
}
@ -943,13 +943,13 @@ bool KeePass1Reader::isMetaStream(const Entry* entry)
QByteArray KeePass1Reader::readKeyfile(QIODevice* device)
{
if (device->size() == 0) {
return QByteArray();
return {};
}
if (device->size() == 32) {
QByteArray data = device->read(32);
if (data.size() != 32) {
return QByteArray();
return {};
}
return data;
@ -959,7 +959,7 @@ QByteArray KeePass1Reader::readKeyfile(QIODevice* device)
QByteArray data = device->read(64);
if (data.size() != 64) {
return QByteArray();
return {};
}
if (Tools::isHex(data)) {
@ -974,7 +974,7 @@ QByteArray KeePass1Reader::readKeyfile(QIODevice* device)
do {
if (!Tools::readFromDevice(device, buffer)) {
return QByteArray();
return {};
}
cryptoHash.addData(buffer);
} while (!buffer.isEmpty());

View File

@ -50,7 +50,7 @@ QByteArray KeePass2RandomStream::randomBytes(int size, bool* ok)
if (m_buffer.size() == m_offset) {
if (!loadBlock()) {
*ok = false;
return QByteArray();
return {};
}
}
@ -71,7 +71,7 @@ QByteArray KeePass2RandomStream::process(const QByteArray& data, bool* ok)
QByteArray randomData = randomBytes(data.size(), &randomBytesOk);
if (!randomBytesOk) {
*ok = false;
return QByteArray();
return {};
}
QByteArray result;

View File

@ -184,7 +184,7 @@ void KeePass2Writer::raiseError(const QString& errorMessage)
*/
QSharedPointer<KdbxWriter> KeePass2Writer::writer() const
{
return QSharedPointer<KdbxWriter>();
return {};
}
/**

View File

@ -301,11 +301,11 @@ QJsonObject OpVaultReader::readAndAssertJsonFile(QFile& file, const QString& str
auto absFilePath = fileInfo.absoluteFilePath();
if (!fileInfo.exists()) {
qCritical() << QString("File \"%1\" must exist").arg(absFilePath);
return QJsonObject();
return {};
}
if (!fileInfo.isReadable()) {
qCritical() << QString("File \"%1\" must be readable").arg(absFilePath);
return QJsonObject();
return {};
}
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -331,7 +331,7 @@ QJsonObject OpVaultReader::readAndAssertJsonFile(QFile& file, const QString& str
QJsonDocument jDoc = QJsonDocument::fromJson(filePayload, error);
if (!jDoc.isObject()) {
qCritical() << "Expected " << filePayload << "to be a JSON Object";
return QJsonObject();
return {};
}
return jDoc.object();
}

View File

@ -64,8 +64,8 @@ QSize CategoryListWidget::sizeHint() const
QSize CategoryListWidget::minimumSizeHint() const
{
return QSize(m_itemDelegate->minWidth() + m_ui->categoryList->frameWidth() * 2,
m_ui->categoryList->sizeHintForRow(0) * 2);
return {m_itemDelegate->minWidth() + m_ui->categoryList->frameWidth() * 2,
m_ui->categoryList->sizeHintForRow(0) * 2};
}
int CategoryListWidget::addCategory(const QString& labelText, const QIcon& icon)

View File

@ -1837,7 +1837,7 @@ QStringList DatabaseWidget::customEntryAttributes() const
{
Entry* entry = m_entryView->currentEntry();
if (!entry) {
return QStringList();
return {};
}
return entry->attributes()->customKeys();

View File

@ -38,7 +38,7 @@ int DefaultIconModel::rowCount(const QModelIndex& parent) const
QVariant DefaultIconModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid()) {
return QVariant();
return {};
}
Q_ASSERT(index.row() < databaseIcons()->count());
@ -47,7 +47,7 @@ QVariant DefaultIconModel::data(const QModelIndex& index, int role) const
return databaseIcons()->icon(index.row(), IconSize::Medium);
}
return QVariant();
return {};
}
CustomIconModel::CustomIconModel(QObject* parent)
@ -78,7 +78,7 @@ int CustomIconModel::rowCount(const QModelIndex& parent) const
QVariant CustomIconModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid()) {
return QVariant();
return {};
}
if (role == Qt::DecorationRole) {
@ -86,7 +86,7 @@ QVariant CustomIconModel::data(const QModelIndex& index, int role) const
return m_icons.value(uuid);
}
return QVariant();
return {};
}
QUuid CustomIconModel::uuidFromIndex(const QModelIndex& index) const

View File

@ -55,9 +55,9 @@ Icons::Icons()
QString Icons::applicationIconName()
{
#ifdef KEEPASSXC_DIST_FLATPAK
return QString("org.keepassxc.KeePassXC");
return "org.keepassxc.KeePassXC";
#else
return QString("keepassxc");
return "keepassxc";
#endif
}

View File

@ -119,12 +119,12 @@ int CsvParserModel::columnCount(const QModelIndex& parent) const
QVariant CsvParserModel::data(const QModelIndex& index, int role) const
{
if ((index.column() >= m_columnHeader.size()) || (index.row() + m_skipped >= rowCount()) || !index.isValid()) {
return QVariant();
return {};
}
if (role == Qt::DisplayRole) {
return m_table.at(index.row() + m_skipped).at(m_columnMap[index.column()]);
}
return QVariant();
return {};
}
QVariant CsvParserModel::headerData(int section, Qt::Orientation orientation, int role) const
@ -132,15 +132,15 @@ QVariant CsvParserModel::headerData(int section, Qt::Orientation orientation, in
if (role == Qt::DisplayRole) {
if (orientation == Qt::Horizontal) {
if ((section < 0) || (section >= m_columnHeader.size())) {
return QVariant();
return {};
}
return m_columnHeader.at(section);
} else if (orientation == Qt::Vertical) {
if (section + m_skipped >= rowCount()) {
return QVariant();
return {};
}
return QString::number(section + 1);
}
}
return QVariant();
return {};
}

View File

@ -79,14 +79,14 @@ QVariant AutoTypeAssociationsModel::headerData(int section, Qt::Orientation orie
return tr("Sequence");
}
} else {
return QVariant();
return {};
}
}
QVariant AutoTypeAssociationsModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid()) {
return QVariant();
return {};
}
if (role == Qt::DisplayRole) {
@ -108,7 +108,7 @@ QVariant AutoTypeAssociationsModel::data(const QModelIndex& index, int role) con
return sequence;
}
} else {
return QVariant();
return {};
}
}

View File

@ -79,7 +79,7 @@ QVariant EntryAttachmentsModel::headerData(int section, Qt::Orientation orientat
QVariant EntryAttachmentsModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid()) {
return QVariant();
return {};
}
if (role == Qt::DisplayRole || role == Qt::EditRole) {
@ -96,7 +96,7 @@ QVariant EntryAttachmentsModel::data(const QModelIndex& index, int role) const
}
}
return QVariant();
return {};
}
bool EntryAttachmentsModel::setData(const QModelIndex& index, const QVariant& value, int role)
@ -124,7 +124,7 @@ Qt::ItemFlags EntryAttachmentsModel::flags(const QModelIndex& index) const
QString EntryAttachmentsModel::keyByIndex(const QModelIndex& index) const
{
if (!index.isValid()) {
return QString();
return {};
}
return m_entryAttachments->keys().at(index.row());

View File

@ -80,14 +80,14 @@ QVariant EntryAttributesModel::headerData(int section, Qt::Orientation orientati
if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole) && (section == 0)) {
return tr("Name");
} else {
return QVariant();
return {};
}
}
QVariant EntryAttributesModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid() || (role != Qt::DisplayRole && role != Qt::EditRole)) {
return QVariant();
return {};
}
return m_attributes.at(index.row());
@ -124,7 +124,7 @@ QModelIndex EntryAttributesModel::indexByKey(const QString& key) const
int row = m_attributes.indexOf(key);
if (row == -1) {
return QModelIndex();
return {};
} else {
return index(row, 0);
}
@ -133,7 +133,7 @@ QModelIndex EntryAttributesModel::indexByKey(const QString& key) const
QString EntryAttributesModel::keyByIndex(const QModelIndex& index) const
{
if (!index.isValid()) {
return QString();
return {};
} else {
return m_attributes.at(index.row());
}

View File

@ -120,7 +120,7 @@ int EntryModel::columnCount(const QModelIndex& parent) const
QVariant EntryModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid()) {
return QVariant();
return {};
}
Entry* entry = entryFromIndex(index);
@ -336,7 +336,7 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
}
}
return QVariant();
return {};
}
QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int role) const

View File

@ -74,7 +74,7 @@ int GroupModel::columnCount(const QModelIndex& parent) const
QModelIndex GroupModel::index(int row, int column, const QModelIndex& parent) const
{
if (!hasIndex(row, column, parent)) {
return QModelIndex();
return {};
}
Group* group;
@ -91,7 +91,7 @@ QModelIndex GroupModel::index(int row, int column, const QModelIndex& parent) co
QModelIndex GroupModel::parent(const QModelIndex& index) const
{
if (!index.isValid()) {
return QModelIndex();
return {};
}
return parent(groupFromIndex(index));
@ -103,7 +103,7 @@ QModelIndex GroupModel::parent(Group* group) const
if (!parentGroup) {
// index is already the root group
return QModelIndex();
return {};
} else {
const Group* grandParentGroup = parentGroup->parentGroup();
if (!grandParentGroup) {
@ -118,7 +118,7 @@ QModelIndex GroupModel::parent(Group* group) const
QVariant GroupModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid()) {
return QVariant();
return {};
}
Group* group = groupFromIndex(index);
@ -145,7 +145,7 @@ QVariant GroupModel::data(const QModelIndex& index, int role) const
}
return tooltip;
} else {
return QVariant();
return {};
}
}
@ -155,7 +155,7 @@ QVariant GroupModel::headerData(int section, Qt::Orientation orientation, int ro
Q_UNUSED(orientation);
Q_UNUSED(role);
return QVariant();
return {};
}
QModelIndex GroupModel::index(Group* group) const

View File

@ -3979,14 +3979,14 @@ QSize BaseStyle::sizeFromContents(ContentsType type,
if (!btn->icon.isNull() || !btn->text.isEmpty())
margins =
proxy()->pixelMetric(isRadio ? PM_RadioButtonLabelSpacing : PM_CheckBoxLabelSpacing, option, widget);
return QSize(size.width() + w + margins, qMax(size.height(), h));
return {size.width() + w + margins, qMax(size.height(), h)};
}
case CT_MenuBarItem: {
int fontHeight = option ? option->fontMetrics.height() : size.height();
auto w = static_cast<int>(fontHeight * Ph::MenuBar_HorizontalPaddingFontRatio);
auto h = static_cast<int>(fontHeight * Ph::MenuBar_VerticalPaddingFontRatio);
int line = Ph::dpiScaled(1);
return QSize(size.width() + w * 2, size.height() + h * 2 + line);
return {size.width() + w * 2, size.height() + h * 2 + line};
}
case CT_MenuItem: {
auto menuItem = qstyleoption_cast<const QStyleOptionMenuItem*>(option);
@ -4113,7 +4113,7 @@ QSize BaseStyle::sizeFromContents(ContentsType type,
xadd += 2;
yadd += 2;
}
return QSize(size.width() + xadd, size.height() + yadd);
return {size.width() + xadd, size.height() + yadd};
}
case CT_ItemViewItem: {
auto vopt = qstyleoption_cast<const QStyleOptionViewItem*>(option);
@ -4335,7 +4335,7 @@ QRect BaseStyle::subControlRect(ComplexControl control,
break;
case SC_SpinBoxDown:
if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
return QRect();
return {};
rect = QRect(x, center, buttonWidth, spinbox->rect.bottom() - center - fw + 1);
break;
@ -4429,13 +4429,13 @@ QRect BaseStyle::subControlRect(ComplexControl control,
case CC_ComboBox: {
auto cb = qstyleoption_cast<const QStyleOptionComboBox*>(option);
if (!cb)
return QRect();
return {};
int frame = cb->frame ? proxy()->pixelMetric(PM_ComboBoxFrameWidth, cb, widget) : 0;
QRect r = option->rect;
r.adjust(frame, frame, -frame, -frame);
int dim = qMin(r.width(), r.height());
if (dim < 1)
return QRect();
return {};
switch (subControl) {
case SC_ComboBoxFrame:
return cb->rect;

View File

@ -30,7 +30,7 @@ ChallengeResponseKey::ChallengeResponseKey(YubiKeySlot keySlot)
QByteArray ChallengeResponseKey::rawKey() const
{
return QByteArray(m_key.data(), m_key.size());
return {m_key.data(), static_cast<int>(m_key.size())};
}
void ChallengeResponseKey::setRawKey(const QByteArray&)

View File

@ -161,7 +161,7 @@ bool FileKey::load(const QString& fileName, QString* errorMsg)
*/
QByteArray FileKey::rawKey() const
{
return QByteArray(m_key.data(), m_key.size());
return {m_key.data(), int(m_key.size())};
}
void FileKey::setRawKey(const QByteArray& data)

View File

@ -44,7 +44,7 @@ QByteArray PasswordKey::rawKey() const
if (!m_isInitialized) {
return {};
}
return QByteArray(m_key.data(), m_key.size());
return {m_key.data(), int(m_key.size())};
}
void PasswordKey::setRawKey(const QByteArray& data)

View File

@ -49,11 +49,11 @@ static QString getNameForHashType(const Totp::Algorithm hashType)
{
switch (hashType) {
case Totp::Algorithm::Sha512:
return QString("SHA512");
return "SHA512";
case Totp::Algorithm::Sha256:
return QString("SHA256");
return "SHA256";
default:
return QString("SHA1");
return "SHA1";
}
}

View File

@ -244,7 +244,7 @@ QDateTime TestKeePass1Reader::genDT(int year, int month, int day, int hour, int
{
QDate date(year, month, day);
QTime time(hour, min, 0);
return QDateTime(date, time, Qt::UTC);
return {date, time, Qt::UTC};
}
void TestKeePass1Reader::reopenDatabase(QSharedPointer<Database> db,