aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-04-02 14:40:05 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-04-02 14:40:05 +0900
commit7ef14023ab337972530bb3f4ad35f8daa326233b (patch)
treeca15ac9869882ceaed5c8a1aa2a082b4d85096df /lib
parentc36f899c4485ebf602fcaf225f41c64fbea773c3 (diff)
downloadlibquotient-7ef14023ab337972530bb3f4ad35f8daa326233b.tar.gz
libquotient-7ef14023ab337972530bb3f4ad35f8daa326233b.zip
Fixes according to results of static analysis
Many thanks to clang-tidy and clazy authors for the tools, and to Qt Creator developers for making them easily available in the IDE.
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.cpp22
-rw-r--r--lib/connection.h2
-rw-r--r--lib/events/roommessageevent.cpp2
-rw-r--r--lib/user.cpp1
4 files changed, 16 insertions, 11 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index a2b1b94e..9d0a34f3 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -148,7 +148,7 @@ void Connection::resolveServer(const QString& mxidOrDomain)
auto domain = maybeBaseUrl.host();
qCDebug(MAIN) << "Finding the server" << domain;
// Check if the Matrix server has a dedicated service record.
- QDnsLookup* dns = new QDnsLookup();
+ auto* dns = new QDnsLookup();
dns->setType(QDnsLookup::SRV);
dns->setName("_matrix._tcp." + domain);
@@ -264,13 +264,13 @@ void Connection::sync(int timeout)
const QString filter { R"({"room": { "timeline": { "limit": 100 } } })" };
auto job = d->syncJob =
callApi<SyncJob>(d->data->lastEvent(), filter, timeout);
- connect( job, &SyncJob::success, [this, job] {
+ connect( job, &SyncJob::success, this, [this, job] {
onSyncSuccess(job->takeData());
d->syncJob = nullptr;
emit syncDone();
});
connect( job, &SyncJob::retryScheduled, this, &Connection::networkError);
- connect( job, &SyncJob::failure, [this, job] {
+ connect( job, &SyncJob::failure, this, [this, job] {
d->syncJob = nullptr;
if (job->error() == BaseJob::ContentAccessError)
emit loginError(job->errorString());
@@ -312,8 +312,9 @@ void Connection::onSyncSuccess(SyncData &&data) {
{
if (accountEvent->type() == EventType::DirectChat)
{
- const auto* event = static_cast<DirectChatEvent*>(accountEvent.get());
- auto usersToDCs = event->usersToDirectChats();
+ const auto usersToDCs =
+ unique_ptr_cast<DirectChatEvent>(accountEvent)
+ ->usersToDirectChats();
DirectChatsMap removals =
erase_if(d->directChats, [&usersToDCs] (auto it) {
return !usersToDCs.contains(it.key()->id(), it.value());
@@ -457,7 +458,7 @@ CreateRoomJob* Connection::createRoom(RoomVisibility visibility,
bool isDirect, bool guestsCanJoin,
const QVector<CreateRoomJob::StateEvent>& initialState,
const QVector<CreateRoomJob::Invite3pid>& invite3pids,
- const QJsonObject creationContent)
+ const QJsonObject& creationContent)
{
auto job = callApi<CreateRoomJob>(
visibility == PublishRoom ? "public" : "private", alias, name,
@@ -479,8 +480,11 @@ void Connection::doInDirectChat(const QString& userId,
{
// There can be more than one DC; find the first valid, and delete invalid
// (left/forgotten) ones along the way.
- for (auto roomId: d->directChats.values(user(userId)))
+ const auto* u = user(userId);
+ for (auto it = d->directChats.find(u);
+ it != d->directChats.end() && it.key() == u; ++it)
{
+ const auto& roomId = *it;
if (auto r = room(roomId, JoinState::Join))
{
Q_ASSERT(r->id() == roomId);
@@ -667,7 +671,7 @@ QVariantHash Connection::accountData(const QString& type) const
QHash<QString, QVector<Room*>> Connection::tagsToRooms() const
{
QHash<QString, QVector<Room*>> result;
- for (auto* r: d->roomMap)
+ for (auto* r: qAsConst(d->roomMap))
{
for (const auto& tagName: r->tagNames())
result[tagName].push_back(r);
@@ -683,7 +687,7 @@ QHash<QString, QVector<Room*>> Connection::tagsToRooms() const
QStringList Connection::tagNames() const
{
QStringList tags ({FavouriteTag});
- for (auto* r: d->roomMap)
+ for (auto* r: qAsConst(d->roomMap))
for (const auto& tag: r->tagNames())
if (tag != LowPriorityTag && !tags.contains(tag))
tags.push_back(tag);
diff --git a/lib/connection.h b/lib/connection.h
index 5a2df012..be414931 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -272,7 +272,7 @@ namespace QMatrixClient
bool guestsCanJoin = false,
const QVector<CreateRoomJob::StateEvent>& initialState = {},
const QVector<CreateRoomJob::Invite3pid>& invite3pids = {},
- const QJsonObject creationContent = {});
+ const QJsonObject& creationContent = {});
/** Get a direct chat with a single user
* This method may return synchronously or asynchoronously depending
diff --git a/lib/events/roommessageevent.cpp b/lib/events/roommessageevent.cpp
index dec0ca50..1a4e74bf 100644
--- a/lib/events/roommessageevent.cpp
+++ b/lib/events/roommessageevent.cpp
@@ -87,7 +87,7 @@ RoomMessageEvent::RoomMessageEvent(const QJsonObject& obj)
_plainBody = content["body"].toString();
_msgtype = content["msgtype"].toString();
- for (auto mt: msgTypes)
+ for (const auto& mt: msgTypes)
if (mt.jsonType == _msgtype)
_content.reset(mt.maker(content));
diff --git a/lib/user.cpp b/lib/user.cpp
index 7a6dbc73..6143a061 100644
--- a/lib/user.cpp
+++ b/lib/user.cpp
@@ -265,6 +265,7 @@ void User::rename(const QString& newName, const Room* r)
qCWarning(MAIN) << "Passing a null room to two-argument User::rename()"
"is incorrect; client developer, please fix it";
rename(newName);
+ return;
}
Q_ASSERT_X(r->memberJoinState(this) == JoinState::Join, __FUNCTION__,
"Attempt to rename a user that's not a room member");