Fix some warnings from PVS-Studio.

Fixes #28667.

Some warnings fixed detailed in this post:
https://pvs-studio.com/en/blog/posts/cpp/1186/
This commit is contained in:
John Preston 2024-11-18 12:50:36 +04:00
parent e4e2f47f8e
commit 9d74d93ed7
18 changed files with 42 additions and 55 deletions

View file

@ -40,6 +40,7 @@ void HandleWithdrawalButton(
std::shared_ptr<Ui::Show> show) { std::shared_ptr<Ui::Show> show) {
Expects(receiver.currencyReceiver Expects(receiver.currencyReceiver
|| (receiver.creditsReceiver && receiver.creditsAmount)); || (receiver.creditsReceiver && receiver.creditsAmount));
struct State { struct State {
rpl::lifetime lifetime; rpl::lifetime lifetime;
bool loading = false; bool loading = false;
@ -58,8 +59,7 @@ void HandleWithdrawalButton(
const auto processOut = [=] { const auto processOut = [=] {
if (state->loading) { if (state->loading) {
return; return;
} } else if (peer && !receiver.creditsAmount()) {
if (peer && !receiver.creditsAmount()) {
return; return;
} }
state->loading = true; state->loading = true;

View file

@ -240,7 +240,8 @@ int LocalStorageBox::Row::resizeGetHeight(int newWidth) {
} }
void LocalStorageBox::Row::paintEvent(QPaintEvent *e) { void LocalStorageBox::Row::paintEvent(QPaintEvent *e) {
if (!_progress || true) { #if 0 // not used
if (!_progress) {
return; return;
} }
auto p = QPainter(this); auto p = QPainter(this);
@ -254,6 +255,7 @@ void LocalStorageBox::Row::paintEvent(QPaintEvent *e) {
st::proxyCheckingPosition.y() + bottom st::proxyCheckingPosition.y() + bottom
}, },
width()); width());
#endif
} }
QString LocalStorageBox::Row::titleText(const Database::TaggedSummary &data) const { QString LocalStorageBox::Row::titleText(const Database::TaggedSummary &data) const {

View file

@ -822,7 +822,7 @@ void StickersListFooter::mousePressEvent(QMouseEvent *e) {
if (e->button() != Qt::LeftButton) { if (e->button() != Qt::LeftButton) {
return; return;
} }
_iconsMousePos = e ? e->globalPos() : QCursor::pos(); _iconsMousePos = e->globalPos();
updateSelected(); updateSelected();
if (_selected == SpecialOver::Settings) { if (_selected == SpecialOver::Settings) {

View file

@ -192,9 +192,7 @@ std::unique_ptr<Lottie::SinglePlayer> LottieThumbnail(
}; };
const auto session = thumb const auto session = thumb
? &thumb->owner()->session() ? &thumb->owner()->session()
: media : &media->owner()->session();
? &media->owner()->session()
: nullptr;
return LottieCachedFromContent( return LottieCachedFromContent(
method, method,
baseKey, baseKey,

View file

@ -189,6 +189,7 @@ void BotGameUrlClickHandler::onClick(ClickContext context) const {
const auto game = media ? media->game() : nullptr; const auto game = media ? media->game() : nullptr;
if (url.startsWith(u"tg://"_q, Qt::CaseInsensitive) || !_bot || !game) { if (url.startsWith(u"tg://"_q, Qt::CaseInsensitive) || !_bot || !game) {
openLink(); openLink();
return;
} }
const auto bot = _bot; const auto bot = _bot;
const auto title = game->title; const auto title = game->title;

View file

@ -126,7 +126,6 @@ void RecentPeers::applyLocal(QByteArray serialized) {
).arg(count)); ).arg(count));
DEBUG_LOG(("Failed bytes: %1.").arg( DEBUG_LOG(("Failed bytes: %1.").arg(
QString::fromUtf8(serialized.mid(streamPosition).toHex()))); QString::fromUtf8(serialized.mid(streamPosition).toHex())));
_list.clear();
return; return;
} }
} }

View file

@ -206,22 +206,20 @@ void Stickers::incrementSticker(not_null<DocumentData*> document) {
auto &sets = setsRef(); auto &sets = setsRef();
auto it = sets.find(Data::Stickers::CloudRecentSetId); auto it = sets.find(Data::Stickers::CloudRecentSetId);
if (it == sets.cend()) { if (it == sets.cend()) {
if (it == sets.cend()) { it = sets.emplace(
it = sets.emplace( Data::Stickers::CloudRecentSetId,
std::make_unique<Data::StickersSet>(
&session().data(),
Data::Stickers::CloudRecentSetId, Data::Stickers::CloudRecentSetId,
std::make_unique<Data::StickersSet>( uint64(0), // accessHash
&session().data(), uint64(0), // hash
Data::Stickers::CloudRecentSetId, tr::lng_recent_stickers(tr::now),
uint64(0), // accessHash QString(),
uint64(0), // hash 0, // count
tr::lng_recent_stickers(tr::now), SetFlag::Special,
QString(), TimeId(0))).first;
0, // count } else {
SetFlag::Special, it->second->title = tr::lng_recent_stickers(tr::now);
TimeId(0))).first;
} else {
it->second->title = tr::lng_recent_stickers(tr::now);
}
} }
const auto set = it->second.get(); const auto set = it->second.get();
auto removedFromEmoji = std::vector<not_null<EmojiPtr>>(); auto removedFromEmoji = std::vector<not_null<EmojiPtr>>();

View file

@ -438,8 +438,6 @@ void ApiWrap::startExport(
} }
if (_settings->types & Settings::Type::AnyChatsMask) { if (_settings->types & Settings::Type::AnyChatsMask) {
_startProcess->steps.push_back(Step::SplitRanges); _startProcess->steps.push_back(Step::SplitRanges);
}
if (_settings->types & Settings::Type::AnyChatsMask) {
_startProcess->steps.push_back(Step::DialogsCount); _startProcess->steps.push_back(Step::DialogsCount);
} }
if (_settings->types & Settings::Type::GroupsChannelsMask) { if (_settings->types & Settings::Type::GroupsChannelsMask) {

View file

@ -869,7 +869,7 @@ HistoryWidget::HistoryWidget(
} }
if (flags & PeerUpdateFlag::FullInfo) { if (flags & PeerUpdateFlag::FullInfo) {
fullInfoUpdated(); fullInfoUpdated();
if (const auto channel = _peer ? _peer->asChannel() : nullptr) { if (const auto channel = _peer->asChannel()) {
if (channel->allowedReactions().paidEnabled) { if (channel->allowedReactions().paidEnabled) {
session().credits().load(); session().credits().load();
} }
@ -3440,7 +3440,7 @@ void HistoryWidget::messagesFailed(const MTP::Error &error, int requestId) {
closeCurrent(); closeCurrent();
const auto wasAccount = not_null(&was->account()); const auto wasAccount = not_null(&was->account());
if (const auto primary = Core::App().windowFor(wasAccount)) { if (const auto primary = Core::App().windowFor(wasAccount)) {
primary->showToast((was && was->isMegagroup()) primary->showToast(was->isMegagroup()
? tr::lng_group_not_accessible(tr::now) ? tr::lng_group_not_accessible(tr::now)
: tr::lng_channel_not_accessible(tr::now)); : tr::lng_channel_not_accessible(tr::now));
} }
@ -5111,7 +5111,7 @@ bool HistoryWidget::updateCmdStartShown() {
const auto textSmall = _fieldCharsCountManager.count() > kSmallMenuAfter; const auto textSmall = _fieldCharsCountManager.count() > kSmallMenuAfter;
const auto textChanged = _botMenu.button const auto textChanged = _botMenu.button
&& ((_botMenu.text != bot->botInfo->botMenuButtonText) && ((_botMenu.text != bot->botInfo->botMenuButtonText)
|| (_botMenu.small != textSmall)); || (_botMenu.small != textSmall));
if (textChanged) { if (textChanged) {
_botMenu.text = bot->botInfo->botMenuButtonText; _botMenu.text = bot->botInfo->botMenuButtonText;
if ((_botMenu.small = textSmall)) { if ((_botMenu.small = textSmall)) {

View file

@ -381,7 +381,7 @@ void FieldHeader::init() {
return; return;
} }
const auto e = static_cast<QMouseEvent*>(event.get()); const auto e = static_cast<QMouseEvent*>(event.get());
const auto pos = e ? e->pos() : mapFromGlobal(QCursor::pos()); const auto pos = e->pos();
const auto inPreviewRect = _clickableRect.contains(pos); const auto inPreviewRect = _clickableRect.contains(pos);
const auto inPhotoEdit = _shownMessageHasPreview const auto inPhotoEdit = _shownMessageHasPreview
&& _photoEditAllowed && _photoEditAllowed
@ -1191,9 +1191,7 @@ void ComposeControls::showStarted() {
if (_attachBotsMenu) { if (_attachBotsMenu) {
_attachBotsMenu->hideFast(); _attachBotsMenu->hideFast();
} }
if (_voiceRecordBar) { _voiceRecordBar->hideFast();
_voiceRecordBar->hideFast();
}
if (_autocomplete) { if (_autocomplete) {
_autocomplete->hideFast(); _autocomplete->hideFast();
} }
@ -1213,9 +1211,7 @@ void ComposeControls::showFinished() {
if (_attachBotsMenu) { if (_attachBotsMenu) {
_attachBotsMenu->hideFast(); _attachBotsMenu->hideFast();
} }
if (_voiceRecordBar) { _voiceRecordBar->hideFast();
_voiceRecordBar->hideFast();
}
if (_autocomplete) { if (_autocomplete) {
_autocomplete->hideFast(); _autocomplete->hideFast();
} }

View file

@ -474,7 +474,7 @@ TTLButton::TTLButton(
) | rpl::start_with_next([=](bool toHide) { ) | rpl::start_with_next([=](bool toHide) {
const auto isFirstTooltip const auto isFirstTooltip
= !Core::App().settings().ttlVoiceClickTooltipHidden(); = !Core::App().settings().ttlVoiceClickTooltipHidden();
if (isFirstTooltip || (!isFirstTooltip && toHide)) { if (isFirstTooltip || toHide) {
_tooltip->toggleAnimated(!toHide); _tooltip->toggleAnimated(!toHide);
} }
}, _tooltip->lifetime()); }, _tooltip->lifetime());

View file

@ -91,7 +91,8 @@ ThemeDocument::ThemeDocument(
: File(parent, parent->data()) : File(parent, parent->data())
, _data(document) , _data(document)
, _serviceWidth(serviceWidth) { , _serviceWidth(serviceWidth) {
Expects(params.has_value() || _data->hasThumbnail() || _data->isTheme()); Expects(params.has_value()
|| (_data && (_data->hasThumbnail() || _data->isTheme())));
if (params) { if (params) {
_background = params->backgroundColors(); _background = params->backgroundColors();

View file

@ -1366,7 +1366,7 @@ void WebViewInstance::show(ShowArgs &&args) {
: attached->inMainMenu : attached->inMainMenu
? Button::RemoveFromMainMenu ? Button::RemoveFromMainMenu
: Button::RemoveFromMenu); : Button::RemoveFromMenu);
const auto allowClipboardRead = v::is<WebViewSourceAttachMenu>(_source) const auto allowClipboardRead = v::is<WebViewSourceMainMenu>(_source)
|| v::is<WebViewSourceAttachMenu>(_source) || v::is<WebViewSourceAttachMenu>(_source)
|| (attached != end(bots) || (attached != end(bots)
&& (attached->inAttachMenu || attached->inMainMenu)); && (attached->inAttachMenu || attached->inMainMenu));

View file

@ -806,10 +806,9 @@ void Mixer::externalSoundProgress(const AudioMsgId &audio) {
} }
bool Mixer::checkCurrentALError(AudioMsgId::Type type) { bool Mixer::checkCurrentALError(AudioMsgId::Type type) {
if (!Audio::PlaybackErrorHappened()) return true; if (!Audio::PlaybackErrorHappened()) {
return true;
const auto data = trackForType(type); } else if (const auto data = trackForType(type)) {
if (!data) {
setStoppedState(data, State::StoppedAtError); setStoppedState(data, State::StoppedAtError);
onError(data->state.id); onError(data->state.id);
} }

View file

@ -1234,7 +1234,8 @@ void OverlayWidget::documentUpdated(not_null<DocumentData*> document) {
if (_document != document) { if (_document != document) {
return; return;
} else if (documentBubbleShown()) { } else if (documentBubbleShown()) {
if ((_document->loading() && _docCancel->isHidden()) || (!_document->loading() && !_docCancel->isHidden())) { if ((_document->loading() && _docCancel->isHidden())
|| (!_document->loading() && !_docCancel->isHidden())) {
updateControls(); updateControls();
} else if (_document->loading()) { } else if (_document->loading()) {
updateDocSize(); updateDocSize();

View file

@ -399,12 +399,10 @@ int32 Session::getState() const {
if (_private) { if (_private) {
const auto s = _private->getState(); const auto s = _private->getState();
if (s == ConnectedState) { if (s == ConnectedState
|| s == ConnectingState
|| s == DisconnectedState) {
return s; return s;
} else if (s == ConnectingState || s == DisconnectedState) {
if (result < 0) {
return s;
}
} else if (s < 0) { } else if (s < 0) {
if (result < 0 && s > result) { if (result < 0 && s > result) {
result = s; result = s;

View file

@ -1059,9 +1059,7 @@ bool ReadSetting(
auto id = Ui::Emoji::IdFromOldKey(static_cast<uint64>(i.key())); auto id = Ui::Emoji::IdFromOldKey(static_cast<uint64>(i.key()));
if (!id.isEmpty()) { if (!id.isEmpty()) {
auto index = Ui::Emoji::ColorIndexFromOldKey(i.value()); auto index = Ui::Emoji::ColorIndexFromOldKey(i.value());
if (index >= 0) { variants.insert(id, index);
variants.insert(id, index);
}
} }
} }
Core::App().settings().setLegacyEmojiVariants(std::move(variants)); Core::App().settings().setLegacyEmojiVariants(std::move(variants));

View file

@ -117,8 +117,7 @@ void ShowOrPremiumBox(
tr::lng_lastseen_shown_toast(tr::now), tr::lng_lastseen_shown_toast(tr::now),
&st::showOrIconLastSeen, &st::showOrIconLastSeen,
} }
: (type == ShowOrPremium::ReadTime) : Skin{
? Skin{
tr::lng_readtime_show_title(), tr::lng_readtime_show_title(),
tr::lng_readtime_show_about( tr::lng_readtime_show_about(
lt_user, lt_user,
@ -134,8 +133,7 @@ void ShowOrPremiumBox(
tr::lng_readtime_premium_button(), tr::lng_readtime_premium_button(),
tr::lng_readtime_shown_toast(tr::now), tr::lng_readtime_shown_toast(tr::now),
&st::showOrIconReadTime, &st::showOrIconReadTime,
} };
: Skin();
box->setStyle(st::showOrBox); box->setStyle(st::showOrBox);
box->setWidth(st::boxWideWidth); box->setWidth(st::boxWideWidth);