Skip to content

Commit c164e4a

Browse files
committed
Fix compiler warnings
Fixes unused-result warnings for functions with nodiscard. Fixes using deprecated QHashCombine without arguments.
1 parent 2744902 commit c164e4a

File tree

10 files changed

+71
-42
lines changed

10 files changed

+71
-42
lines changed

plugins/itemfakevim/fakevim/fakevimhandler.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6389,11 +6389,15 @@ bool FakeVimHandler::Private::handleExWriteCommand(const ExCommand &cmd)
63896389
}
63906390
// Check result by reading back.
63916391
QFile file3(fileName);
6392-
file3.open(QIODevice::ReadOnly);
6393-
QByteArray ba = file3.readAll();
6394-
showMessage(MessageInfo, Tr::tr("\"%1\" %2 %3L, %4C written.")
6395-
.arg(fileName).arg(exists ? QString(" ") : Tr::tr(" [New] "))
6396-
.arg(ba.count('\n')).arg(ba.size()));
6392+
if (file3.open(QIODevice::ReadOnly)) {
6393+
QByteArray ba = file3.readAll();
6394+
showMessage(MessageInfo, Tr::tr("\"%1\" %2 %3L, %4C written.")
6395+
.arg(fileName).arg(exists ? QString(" ") : Tr::tr(" [New] "))
6396+
.arg(ba.count('\n')).arg(ba.size()));
6397+
} else {
6398+
showMessage(MessageError, Tr::tr
6399+
("Cannot open file \"%1\" for reading").arg(fileName));
6400+
}
63976401
//if (quitAll)
63986402
// passUnknownExCommand(forced ? "qa!" : "qa");
63996403
//else if (quit)
@@ -6419,7 +6423,11 @@ bool FakeVimHandler::Private::handleExReadCommand(const ExCommand &cmd)
64196423

64206424
m_currentFileName = replaceTildeWithHome(cmd.args);
64216425
QFile file(m_currentFileName);
6422-
file.open(QIODevice::ReadOnly);
6426+
if (!file.open(QIODevice::ReadOnly)) {
6427+
showMessage(MessageError, Tr::tr
6428+
("Cannot open file \"%1\" for reading").arg(m_currentFileName));
6429+
return true;
6430+
}
64236431
QTextStream ts(&file);
64246432
QString data = ts.readAll();
64256433
insertText(data);

src/app/applicationexceptionhandler.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
void logException(const char *what)
1212
{
1313
QFile f;
14-
f.open(stderr, QIODevice::WriteOnly);
15-
f.write(what ? what : "Unknown exception");
16-
f.write("\n");
17-
f.close();
14+
if ( f.open(stderr, QIODevice::WriteOnly) ) {
15+
f.write(what ? what : "Unknown exception");
16+
f.write("\n");
17+
f.close();
18+
}
1819

1920
log( QString("Exception: ") + what, LogError );
2021
}

src/app/clipboardserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace {
5555
uint monitorCommandStateHash(const QVector<Command> &commands)
5656
{
5757
uint seed = 0;
58-
QtPrivate::QHashCombine hash;
58+
QtPrivate::QHashCombine hash(seed);
5959

6060
for (const auto &command : commands) {
6161
if (command.type() == CommandType::Script)

src/common/log.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ void logAlways(const QByteArray &msgText, const LogLevel level)
112112
// Log to file and if needed to stderr.
113113
if ( !writtenToLogFile || level <= LogWarning || hasLogLevel(LogDebug) ) {
114114
QFile ferr;
115-
ferr.open(stderr, QIODevice::WriteOnly);
116-
const auto simpleMsg = createSimpleLogMessage(msgText, level);
117-
ferr.write(simpleMsg);
115+
if ( ferr.open(stderr, QIODevice::WriteOnly) ) {
116+
const auto simpleMsg = createSimpleLogMessage(msgText, level);
117+
ferr.write(simpleMsg);
118+
}
118119
}
119120
}
120121

src/common/textdata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ bool isPluginFormat(const QString &mime)
3636
uint hash(const QVariantMap &data)
3737
{
3838
uint seed = 0;
39-
QtPrivate::QHashCombine hash;
39+
QtPrivate::QHashCombine hash(seed);
4040

4141
for (auto it = data.constBegin(); it != data.constEnd(); ++it) {
4242
const auto &mime = it.key();

src/gui/actiondialog.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212

1313
#include <QAbstractButton>
1414
#include <QFile>
15+
#include <QLoggingCategory>
1516
#include <QMessageBox>
1617
#include <QShortcut>
1718

18-
#include <memory>
19-
2019
namespace {
2120

21+
Q_DECLARE_LOGGING_CATEGORY(logCategory)
22+
Q_LOGGING_CATEGORY(logCategory, "copyq.actiondialog")
23+
2224
void initFormatComboBox(QComboBox *combo, const QStringList &additionalFormats = QStringList())
2325
{
2426
QStringList formats = QStringList() << QString() << QString(mimeText) << additionalFormats;
@@ -100,21 +102,29 @@ void ActionDialog::restoreHistory()
100102
{
101103
const int maxCount = AppConfig().option<Config::command_history_size>();
102104
ui->comboBoxCommands->setMaxCount(maxCount + 1);
105+
ui->comboBoxCommands->clear();
106+
ui->comboBoxCommands->addItem(QString());
107+
ui->comboBoxCommands->setCurrentIndex(0);
103108

104109
QFile file( dataFilename() );
105-
file.open(QIODevice::ReadOnly);
110+
if ( !file.exists() )
111+
return;
112+
113+
if ( !file.open(QIODevice::ReadOnly) ) {
114+
qCWarning(logCategory) << "Failed to restore Action dialog history from"
115+
<< file.fileName() << ":" << file.errorString();
116+
return;
117+
}
118+
106119
QDataStream in(&file);
107120
QVariant v;
108121

109-
ui->comboBoxCommands->clear();
110-
ui->comboBoxCommands->addItem(QString());
111122
while( !in.atEnd() && ui->comboBoxCommands->count() <= maxCount ) {
112123
in >> v;
113124
const QVariantMap values = v.value<QVariantMap>();
114125
const QString cmd = values.value("cmd").toString();
115126
ui->comboBoxCommands->addItem( commandToLabel(cmd), v );
116127
}
117-
ui->comboBoxCommands->setCurrentIndex(0);
118128
}
119129

120130
const QString ActionDialog::dataFilename() const
@@ -125,7 +135,12 @@ const QString ActionDialog::dataFilename() const
125135
void ActionDialog::saveHistory()
126136
{
127137
QFile file( dataFilename() );
128-
file.open(QIODevice::WriteOnly);
138+
if ( !file.open(QIODevice::WriteOnly) ) {
139+
qCWarning(logCategory) << "Failed to save Action dialog history to"
140+
<< file.fileName() << ":" << file.errorString();
141+
return;
142+
}
143+
129144
QDataStream out(&file);
130145

131146
for (int i = 1; i < ui->comboBoxCommands->count(); ++i) {

src/gui/actionhandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void ActionHandler::closeAction(Action *action)
145145
void ActionHandler::showActionErrors(Action *action, const QString &message, ushort icon)
146146
{
147147
m_actionModel->actionFailed(action, message);
148-
QtPrivate::QHashCombine hash;
148+
QtPrivate::QHashCombine hash(0);
149149
const auto notificationId = QString::number( hash(hash(0, action->commandLine()), message) );
150150
if ( m_notificationDaemon->findNotification(notificationId) )
151151
return;

src/gui/commanddialog.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,13 @@ void CommandDialog::onPushButtonSaveCommandsClicked()
272272
fileName.append(".ini");
273273

274274
QFile ini(fileName);
275-
ini.open(QIODevice::WriteOnly);
275+
if ( !ini.open(QIODevice::WriteOnly) ) {
276+
QMessageBox::warning(
277+
this, tr("Save Commands"),
278+
tr("Failed to save commands to file \"%1\": %2")
279+
.arg(fileName, ini.errorString()) );
280+
return;
281+
}
276282
ini.write(serializeSelectedCommands().toUtf8());
277283
}
278284
}

src/main.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,12 @@ int evaluate(
6565
const auto output = scriptable.serializeScriptValue(result);
6666
if ( !output.isEmpty() ) {
6767
QFile f;
68-
if (hasUncaughtException)
69-
f.open(stderr, QIODevice::WriteOnly);
70-
else
71-
f.open(stdout, QIODevice::WriteOnly);
72-
73-
f.write(output);
74-
if ( !output.endsWith("\n") )
75-
f.write("\n");
76-
f.close();
68+
if ( f.open(hasUncaughtException ? stderr : stdout, QIODevice::WriteOnly) ) {
69+
f.write(output);
70+
if ( !output.endsWith("\n") )
71+
f.write("\n");
72+
f.close();
73+
}
7774
}
7875

7976
const int exitCode = hasUncaughtException ? CommandException : 0;

src/scriptable/scriptable.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,7 +2895,7 @@ void Scriptable::showExceptionMessage(const QString &message)
28952895
? tr("Exception")
28962896
: tr("Exception in %1").arg( quoteString(m_actionName) );
28972897

2898-
QtPrivate::QHashCombine hash;
2898+
QtPrivate::QHashCombine hash(0);
28992899
MessageData messageData;
29002900
const auto id = hash(hash(0, title), message);
29012901
messageData.notificationId = QString::number(id);
@@ -3392,8 +3392,8 @@ void Scriptable::print(const QByteArray &message)
33923392
m_action->appendOutput(message);
33933393
} else {
33943394
QFile f;
3395-
f.open(stdout, QIODevice::WriteOnly);
3396-
f.write(message);
3395+
if ( f.open(stdout, QIODevice::WriteOnly) )
3396+
f.write(message);
33973397
}
33983398
}
33993399

@@ -3403,10 +3403,11 @@ void Scriptable::printError(const QByteArray &message)
34033403
m_action->appendErrorOutput(message);
34043404
} else {
34053405
QFile f;
3406-
f.open(stderr, QIODevice::WriteOnly);
3407-
f.write(message);
3408-
if ( !message.endsWith('\n') )
3409-
f.write("\n");
3406+
if ( f.open(stderr, QIODevice::WriteOnly) ) {
3407+
f.write(message);
3408+
if ( !message.endsWith('\n') )
3409+
f.write("\n");
3410+
}
34103411
}
34113412
}
34123413

@@ -3542,8 +3543,8 @@ QJSValue Scriptable::readInput()
35423543
protected:
35433544
void run() override {
35443545
QFile in;
3545-
in.open(stdin, QIODevice::ReadOnly);
3546-
input = in.readAll();
3546+
if ( in.open(stdin, QIODevice::ReadOnly) )
3547+
input = in.readAll();
35473548
}
35483549
};
35493550

0 commit comments

Comments
 (0)