From b8104863a5be3e6f3e70d84539678d6d61fc4928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolf=20Cl=C3=A9ment?= Date: Sun, 20 Dec 2020 09:38:34 +0100 Subject: [PATCH] Fix crash when receiving whisper (#2298) PR #2284 introduced this bug: whispers aren't linked to a twitch channel but we're storing user colors in a twitch channel. So, dereferencing a nullptr. Not good. --- src/common/ChannelChatters.cpp | 2 +- src/providers/twitch/TwitchMessageBuilder.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/common/ChannelChatters.cpp b/src/common/ChannelChatters.cpp index be5bacb9..4728aef9 100644 --- a/src/common/ChannelChatters.cpp +++ b/src/common/ChannelChatters.cpp @@ -72,7 +72,7 @@ void ChannelChatters::setChatters(UsernameSet &&set) const QColor ChannelChatters::getUserColor(const QString &user) { - const auto chatterColors = this->chatterColors_.access(); + const auto chatterColors = this->chatterColors_.accessConst(); const auto search = chatterColors->find(user.toLower()); if (search == chatterColors->end()) diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 5629ffca..0b93270f 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -600,7 +600,10 @@ void TwitchMessageBuilder::parseUsername() // } this->message().loginName = this->userName; - this->twitchChannel->setUserColor(this->userName, this->usernameColor_); + if (this->twitchChannel != nullptr) + { + this->twitchChannel->setUserColor(this->userName, this->usernameColor_); + } // Update current user color if this is our message auto currentUser = getApp()->accounts->twitch.getCurrent();