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

View file

@ -240,7 +240,8 @@ int LocalStorageBox::Row::resizeGetHeight(int newWidth) {
}
void LocalStorageBox::Row::paintEvent(QPaintEvent *e) {
if (!_progress || true) {
#if 0 // not used
if (!_progress) {
return;
}
auto p = QPainter(this);
@ -254,6 +255,7 @@ void LocalStorageBox::Row::paintEvent(QPaintEvent *e) {
st::proxyCheckingPosition.y() + bottom
},
width());
#endif
}
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) {
return;
}
_iconsMousePos = e ? e->globalPos() : QCursor::pos();
_iconsMousePos = e->globalPos();
updateSelected();
if (_selected == SpecialOver::Settings) {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -381,7 +381,7 @@ void FieldHeader::init() {
return;
}
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 inPhotoEdit = _shownMessageHasPreview
&& _photoEditAllowed
@ -1191,9 +1191,7 @@ void ComposeControls::showStarted() {
if (_attachBotsMenu) {
_attachBotsMenu->hideFast();
}
if (_voiceRecordBar) {
_voiceRecordBar->hideFast();
}
_voiceRecordBar->hideFast();
if (_autocomplete) {
_autocomplete->hideFast();
}
@ -1213,9 +1211,7 @@ void ComposeControls::showFinished() {
if (_attachBotsMenu) {
_attachBotsMenu->hideFast();
}
if (_voiceRecordBar) {
_voiceRecordBar->hideFast();
}
_voiceRecordBar->hideFast();
if (_autocomplete) {
_autocomplete->hideFast();
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1059,9 +1059,7 @@ bool ReadSetting(
auto id = Ui::Emoji::IdFromOldKey(static_cast<uint64>(i.key()));
if (!id.isEmpty()) {
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));

View file

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