Misc: Fix a bunch of code analysis warnings

Quite a few of these were legitimate.
This commit is contained in:
Stenzek 2025-03-30 23:55:02 +10:00
parent c7139b943c
commit bbdc6ab4e0
No known key found for this signature in database
27 changed files with 54 additions and 64 deletions

View File

@ -272,7 +272,7 @@ public:
ALWAYS_INLINE BinaryFileReader& operator>>(s64& val) { val = ReadT<s64>(); return *this; }
ALWAYS_INLINE BinaryFileReader& operator>>(u64& val) { val = ReadT<u64>(); return *this; }
ALWAYS_INLINE BinaryFileReader& operator>>(float& val) { val = ReadT<float>(); return *this; }
ALWAYS_INLINE BinaryFileReader& operator>>(std::string_view& val) { val = ReadCString(); return *this; }
ALWAYS_INLINE BinaryFileReader& operator>>(std::string& val) { val = ReadCString(); return *this; }
// clang-format on
template<typename T>

View File

@ -223,7 +223,7 @@ public:
}
}
DynamicHeapArray(this_type&& move)
DynamicHeapArray(this_type&& move) noexcept
{
m_data = move.m_data;
m_size = move.m_size;
@ -358,7 +358,7 @@ public:
return *this;
}
this_type& operator=(this_type&& move)
this_type& operator=(this_type&& move) noexcept
{
assign(std::move(move));
return *this;

View File

@ -737,13 +737,14 @@ std::optional<size_t> StringUtil::BytePatternSearch(const std::span<const u8> by
return std::nullopt;
const bool allocate_on_heap = (pattern_length >= 512);
u8* match_bytes = allocate_on_heap ? static_cast<u8*>(alloca(pattern_length * 2)) : new u8[pattern_length * 2];
u8* match_bytes = allocate_on_heap ? new u8[pattern_length * 2] : static_cast<u8*>(alloca(pattern_length * 2));
u8* match_masks = match_bytes + pattern_length;
hinibble = true;
u8 match_byte = 0;
u8 match_mask = 0;
for (size_t i = 0, match_len = 0; i < pattern.size(); i++)
size_t match_len = 0;
for (size_t i = 0; i < pattern.size(); i++)
{
u8 nibble = 0, nibble_mask = 0xF;
if (pattern[i] >= '0' && pattern[i] <= '9')
@ -772,8 +773,8 @@ std::optional<size_t> StringUtil::BytePatternSearch(const std::span<const u8> by
match_mask = nibble_mask;
}
}
if (pattern_length == 0)
return std::nullopt;
DebugAssert(match_len == pattern_length);
std::optional<size_t> ret;
const size_t max_search_offset = bytes.size() - pattern_length;

View File

@ -2884,7 +2884,7 @@ void Achievements::DrawAchievementsWindow()
progress_bb.Min.y + ((progress_bb.Max.y - progress_bb.Min.y) / 2.0f) - (text_size.y / 2.0f));
dl->AddText(UIStyle.MediumFont, UIStyle.MediumFont->FontSize, text_pos,
ImGui::GetColorU32(UIStyle.PrimaryTextColor), text.c_str(), text.end_ptr());
top += progress_height + spacing;
// top += progress_height + spacing;
}
}
}

View File

@ -109,8 +109,8 @@ private:
// Transmit and receive buffers, not including the first Hi-Z/ack response byte
static constexpr u32 MAX_RESPONSE_LENGTH = 8;
std::array<u8, MAX_RESPONSE_LENGTH> m_rx_buffer;
std::array<u8, MAX_RESPONSE_LENGTH> m_tx_buffer;
std::array<u8, MAX_RESPONSE_LENGTH> m_rx_buffer{};
std::array<u8, MAX_RESPONSE_LENGTH> m_tx_buffer{};
// Get number of response halfwords (excluding the initial controller info halfword)
u8 GetResponseNumHalfwords() const;

View File

@ -465,7 +465,7 @@ struct CDROMState
XorShift128PlusPlus prng;
std::array<SectorBuffer, NUM_SECTOR_BUFFERS> sector_buffers;
std::array<SectorBuffer, NUM_SECTOR_BUFFERS> sector_buffers = {};
u32 current_read_sector_buffer = 0;
u32 current_write_sector_buffer = 0;
@ -927,7 +927,7 @@ bool CDROM::CanReadMedia()
return (s_state.drive_state != DriveState::ShellOpening && s_reader.HasMedia());
}
bool CDROM::InsertMedia(std::unique_ptr<CDImage> media, DiscRegion region, std::string_view serial,
bool CDROM::InsertMedia(std::unique_ptr<CDImage>& media, DiscRegion region, std::string_view serial,
std::string_view title, Error* error)
{
// Load SBI/LSD first.

View File

@ -30,7 +30,7 @@ bool IsMediaPS1Disc();
bool IsMediaAudioCD();
bool DoesMediaRegionMatchConsole();
bool InsertMedia(std::unique_ptr<CDImage> media, DiscRegion region, std::string_view serial, std::string_view title,
bool InsertMedia(std::unique_ptr<CDImage>& media, DiscRegion region, std::string_view serial, std::string_view title,
Error* error);
std::unique_ptr<CDImage> RemoveMedia(bool for_disc_swap);
bool PrecacheMedia();

View File

@ -409,12 +409,10 @@ void ImGuiManager::DrawPerformanceOverlay(const GPUBackend* gpu, float& position
if (CPU::g_state.using_interpreter)
{
text.append_format("{}{}", first ? "" : "/", "I");
first = false;
}
else if (g_settings.cpu_execution_mode == CPUExecutionMode::CachedInterpreter)
{
text.append_format("{}{}", first ? "" : "/", "CI");
first = false;
}
else
{
@ -424,10 +422,7 @@ void ImGuiManager::DrawPerformanceOverlay(const GPUBackend* gpu, float& position
first = false;
}
if (g_settings.cpu_recompiler_memory_exceptions)
{
text.append_format("{}{}", first ? "" : "/", "ME");
first = false;
}
}
text.append("]: ");

View File

@ -276,11 +276,7 @@ void MDEC::DMARead(u32* words, u32 word_count)
const u32 words_to_read = std::min(word_count, s_state.data_out_fifo.GetSize());
if (words_to_read > 0)
{
s_state.data_out_fifo.PopRange(words, words_to_read);
words += words_to_read;
word_count -= words_to_read;
}
DEBUG_LOG("DMA read complete, {} bytes left", s_state.data_out_fifo.GetSize() * sizeof(u32));
if (s_state.data_out_fifo.IsEmpty())

View File

@ -1901,8 +1901,7 @@ bool System::Initialize(std::unique_ptr<CDImage> disc, DiscRegion disc_region, b
return false;
// CDROM before GPU, that way we don't modeswitch.
if (disc &&
!CDROM::InsertMedia(std::move(disc), disc_region, s_state.running_game_serial, s_state.running_game_title, error))
if (disc && !CDROM::InsertMedia(disc, disc_region, s_state.running_game_serial, s_state.running_game_title, error))
return false;
// TODO: Drop class
@ -2921,8 +2920,8 @@ bool System::LoadStateFromBuffer(const SaveStateBuffer& buffer, Error* error, bo
(media_subimage_index != 0 && new_disc->HasSubImages() &&
!new_disc->SwitchSubImage(media_subimage_index, error ? error : &local_error)) ||
(UpdateRunningGame(buffer.media_path, new_disc.get(), false),
!CDROM::InsertMedia(std::move(new_disc), new_disc_region, s_state.running_game_serial,
s_state.running_game_title, error ? error : &local_error)))
!CDROM::InsertMedia(new_disc, new_disc_region, s_state.running_game_serial, s_state.running_game_title,
error ? error : &local_error)))
{
if (CDROM::HasMedia())
{
@ -4070,9 +4069,8 @@ bool System::InsertMedia(const char* path)
std::unique_ptr<CDImage> image = CDImage::Open(path, g_settings.cdrom_load_image_patches, &error);
const DiscRegion region =
image ? GameList::GetCustomRegionForPath(path).value_or(GetRegionForImage(image.get())) : DiscRegion::NonPS1;
if (!image ||
(UpdateRunningGame(path, image.get(), false),
!CDROM::InsertMedia(std::move(image), region, s_state.running_game_serial, s_state.running_game_title, &error)))
if (!image || (UpdateRunningGame(path, image.get(), false),
!CDROM::InsertMedia(image, region, s_state.running_game_serial, s_state.running_game_title, &error)))
{
Host::AddIconOSDWarning(
"DiscInserted", ICON_FA_COMPACT_DISC,
@ -4327,8 +4325,7 @@ bool System::SwitchMediaSubImage(u32 index)
subimage_title = image->GetSubImageMetadata(index, "title");
title = image->GetMetadata("title");
UpdateRunningGame(image->GetPath(), image.get(), false);
okay =
CDROM::InsertMedia(std::move(image), region, s_state.running_game_serial, s_state.running_game_title, &error);
okay = CDROM::InsertMedia(image, region, s_state.running_game_serial, s_state.running_game_title, &error);
}
if (!okay)
{
@ -4342,7 +4339,7 @@ bool System::SwitchMediaSubImage(u32 index)
const DiscRegion region =
GameList::GetCustomRegionForPath(image->GetPath()).value_or(GetRegionForImage(image.get()));
UpdateRunningGame(image->GetPath(), image.get(), false);
CDROM::InsertMedia(std::move(image), region, s_state.running_game_serial, s_state.running_game_title, nullptr);
CDROM::InsertMedia(image, region, s_state.running_game_serial, s_state.running_game_title, nullptr);
return false;
}
@ -4783,7 +4780,8 @@ void System::WarnAboutUnsafeSettings()
if (g_settings.cdrom_read_speedup != 1 || g_settings.cdrom_seek_speedup != 1)
append(ICON_EMOJI_WARNING, TRANSLATE_SV("System", "CD-ROM read/seek speedup is enabled. This may crash games."));
if (g_settings.gpu_force_video_timing != ForceVideoTimingMode::Disabled)
append(ICON_FA_TV, TRANSLATE_SV("System", "Frame rate is not set to automatic. Games may run at incorrect speeds."));
append(ICON_FA_TV,
TRANSLATE_SV("System", "Frame rate is not set to automatic. Games may run at incorrect speeds."));
if (!g_settings.IsUsingSoftwareRenderer())
{
if (g_settings.gpu_multisamples != 1)

View File

@ -138,7 +138,7 @@ AudioBackend AudioSettingsWidget::getEffectiveBackend() const
void AudioSettingsWidget::updateDriverNames()
{
const AudioBackend backend = getEffectiveBackend();
const std::vector<std::pair<std::string, std::string>> names = AudioStream::GetDriverNames(backend);
std::vector<std::pair<std::string, std::string>> names = AudioStream::GetDriverNames(backend);
m_ui.driver->disconnect();
m_ui.driver->clear();
@ -166,7 +166,7 @@ void AudioSettingsWidget::updateDeviceNames()
const AudioBackend backend = getEffectiveBackend();
const std::string driver_name = m_dialog->getEffectiveStringValue("Audio", "Driver", "");
const std::string current_device = m_dialog->getEffectiveStringValue("Audio", "Device", "");
const std::vector<AudioStream::DeviceInfo> devices =
std::vector<AudioStream::DeviceInfo> devices =
AudioStream::GetOutputDevices(backend, driver_name.c_str(), SPU::SAMPLE_RATE);
m_ui.outputDevice->disconnect();

View File

@ -78,9 +78,9 @@ void GamePatchSettingsWidget::disableAllPatches()
void GamePatchSettingsWidget::reloadList()
{
const std::vector<Cheats::CodeInfo> patches =
std::vector<Cheats::CodeInfo> patches =
Cheats::GetCodeInfoList(m_dialog->getGameSerial(), std::nullopt, false, true, true);
const std::vector<std::string> enabled_list =
std::vector<std::string> enabled_list =
m_dialog->getSettingsInterface()->GetStringList(Cheats::PATCHES_CONFIG_SECTION, Cheats::PATCH_ENABLE_CONFIG_KEY);
delete m_ui.scrollArea->takeWidget();
@ -93,7 +93,7 @@ void GamePatchSettingsWidget::reloadList()
{
bool first = true;
for (const Cheats::CodeInfo& pi : patches)
for (Cheats::CodeInfo& pi : patches)
{
if (!first)
{

View File

@ -216,8 +216,8 @@ void InputBindingDialog::addNewBinding()
if (m_new_bindings.empty())
return;
const std::string new_binding(
InputManager::ConvertInputBindingKeysToString(m_bind_type, m_new_bindings.data(), m_new_bindings.size()));
std::string new_binding =
InputManager::ConvertInputBindingKeysToString(m_bind_type, m_new_bindings.data(), m_new_bindings.size());
if (!new_binding.empty())
{
if (std::find(m_bindings.begin(), m_bindings.end(), new_binding) != m_bindings.end())

View File

@ -106,10 +106,10 @@ bool MemoryCardEditorWindow::setCardB(const QString& path)
bool MemoryCardEditorWindow::createMemoryCard(const QString& path, Error* error)
{
MemoryCardImage::DataArray data;
MemoryCardImage::Format(&data);
std::unique_ptr<MemoryCardImage::DataArray> data = std::make_unique<MemoryCardImage::DataArray>();
MemoryCardImage::Format(data.get());
return MemoryCardImage::SaveToFile(data, path.toUtf8().constData(), error);
return MemoryCardImage::SaveToFile(*data.get(), path.toUtf8().constData(), error);
}
void MemoryCardEditorWindow::resizeEvent(QResizeEvent* ev)

View File

@ -280,7 +280,6 @@ void MemoryViewWidget::paintEvent(QPaintEvent* event)
int x;
int lx = addressWidth();
painter.drawLine(lx - offsetX, 0, lx - offsetX, height());
y = m_char_height;
// hex data
const int HEX_CHAR_WIDTH = 4 * m_char_width;

View File

@ -172,7 +172,7 @@ void PostProcessingChainConfigWidget::onAddButtonClicked()
{
QMenu menu;
const std::vector<std::pair<std::string, std::string>> shaders = PostProcessing::GetAvailableShaderNames();
std::vector<std::pair<std::string, std::string>> shaders = PostProcessing::GetAvailableShaderNames();
if (shaders.empty())
{
menu.addAction(tr("No Shaders Available"))->setEnabled(false);
@ -257,7 +257,7 @@ void PostProcessingChainConfigWidget::onMoveUpButtonClicked()
void PostProcessingChainConfigWidget::onMoveDownButtonClicked()
{
std::optional<u32> index = getSelectedIndex();
if (index.has_value() || index.value() < (static_cast<u32>(m_ui.stages->count() - 1)))
if (index.has_value() && index.value() < (static_cast<u32>(m_ui.stages->count() - 1)))
{
auto lock = Host::GetSettingsLock();
SettingsInterface& si = getSettingsInterfaceToUpdate();

View File

@ -51,8 +51,7 @@ SettingsWindow::SettingsWindow() : QWidget()
SettingsWindow::SettingsWindow(const std::string& path, std::string title, std::string serial, GameHash hash,
DiscRegion region, const GameDatabase::Entry* entry,
std::unique_ptr<INISettingsInterface> sif)
: QWidget(), m_sif(std::move(sif)), m_database_entry(entry), m_title(std::move(title)), m_serial(std::move(serial)),
m_hash(hash)
: QWidget(), m_sif(std::move(sif)), m_database_entry(entry), m_serial(std::move(serial)), m_hash(hash)
{
m_ui.setupUi(this);
setGameTitle(std::move(title));

View File

@ -500,7 +500,7 @@ struct SettingAccessor<QSpinBox>
else
{
widget->setContextMenuPolicy(Qt::CustomContextMenu);
widget->connect(widget, &QSpinBox::customContextMenuRequested, widget, [widget, func](const QPoint& pt) {
widget->connect(widget, &QSpinBox::customContextMenuRequested, widget, [widget, func](const QPoint& pt) mutable {
QMenu menu(widget);
widget->connect(menu.addAction(qApp->translate("SettingWidgetBinder", "Reset")), &QAction::triggered, widget,
[widget, func = std::move(func)]() {

View File

@ -54,7 +54,7 @@ bool CDImageMemory::CopyImage(CDImage* image, ProgressCallback* progress)
m_memory_sectors += image->GetIndex(i).length;
}
if ((static_cast<u64>(RAW_SECTOR_SIZE) * static_cast<u64>(m_memory_sectors)) >=
if (m_memory_sectors == 0 || (static_cast<u64>(RAW_SECTOR_SIZE) * static_cast<u64>(m_memory_sectors)) >=
static_cast<u64>(std::numeric_limits<size_t>::max()))
{
progress->ModalError("Insufficient address space");

View File

@ -1906,7 +1906,6 @@ void D3D12Device::BeginRenderPass()
D3D12Texture* const ds = m_current_depth_target;
ds->TransitionToState(cmdlist, D3D12_RESOURCE_STATE_DEPTH_WRITE);
ds->SetUseFenceValue(GetCurrentFenceValue());
ds_desc_p = &ds_desc;
ds_desc.cpuDescriptor = ds->GetWriteDescriptor();
ds_desc.DepthEndingAccess.Type = D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE;
ds_desc.StencilBeginningAccess = {};
@ -2059,13 +2058,9 @@ bool D3D12Device::IsRenderTargetBound(const GPUTexture* tex) const
void D3D12Device::InvalidateCachedState()
{
DebugAssert(!m_in_render_pass);;
m_dirty_flags = ALL_DIRTY_STATE &
((m_current_render_pass_flags & GPUPipeline::BindRenderTargetsAsImages) ? ~0u : ~DIRTY_FLAG_RT_UAVS);
m_in_render_pass = false;
m_current_pipeline = nullptr;
m_current_vertex_stride = 0;
m_current_blend_constant = 0;
m_current_topology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED;
}
void D3D12Device::SetInitialPipelineState()

View File

@ -73,7 +73,9 @@ D3D12Pipeline::D3D12Pipeline(Microsoft::WRL::ComPtr<ID3D12PipelineState> pipelin
D3D12Pipeline::~D3D12Pipeline()
{
D3D12Device::GetInstance().DeferObjectDestruction(std::move(m_pipeline));
D3D12Device& dev = D3D12Device::GetInstance();
dev.UnbindPipeline(this);
dev.DeferObjectDestruction(std::move(m_pipeline));
}
#ifdef ENABLE_GPU_OBJECT_NAMES

View File

@ -227,7 +227,7 @@ bool DInputSource::AddDevice(ControllerData& cd, const std::string& name)
range.diph.dwObj = static_cast<DWORD>(offset);
range.lMin = std::numeric_limits<s16>::min();
range.lMax = std::numeric_limits<s16>::max();
hr = cd.device->SetProperty(DIPROP_RANGE, &range.diph);
cd.device->SetProperty(DIPROP_RANGE, &range.diph);
// did it apply?
if (SUCCEEDED(cd.device->GetProperty(DIPROP_RANGE, &range.diph)))

View File

@ -1188,7 +1188,7 @@ std::unique_ptr<GPUTexture> GPUDevice::FetchTexture(u32 width, u32 height, u32 l
error ? error : &create_error, "Failed to create {}x{} {} {}: {}", width, height,
GPUTexture::GetFormatName(format),
((type == GPUTexture::Type::RenderTarget) ? "RT" : (type == GPUTexture::Type::DepthStencil ? "DS" : "Texture")),
create_error.TakeDescription());
create_error.GetDescription());
if (!error)
ERROR_LOG(create_error.GetDescription());
}

View File

@ -141,7 +141,7 @@ std::string InputSource::ConvertGenericControllerKeyToString(InputBindingKey key
{
if (key.source_subtype == InputSubclass::ControllerAxis)
{
const char* modifier = "";
const char* modifier;
switch (key.modifier)
{
case InputModifier::None:
@ -153,6 +153,9 @@ std::string InputSource::ConvertGenericControllerKeyToString(InputBindingKey key
case InputModifier::FullAxis:
modifier = "Full";
break;
default:
modifier = "";
break;
}
return fmt::format("{}-{}/{}Axis{}", InputManager::InputSourceToString(key.source_type),
static_cast<u32>(key.source_index), modifier, key.data);

View File

@ -1652,6 +1652,7 @@ bool MediaCaptureMF::GetAudioTypes(std::string_view codec, ComPtr<IMFMediaType>*
if (output_subtype == AUDIO_INPUT_MEDIA_FORMAT)
{
*output_type = std::move(*input_type);
*input_type = ComPtr<IMFMediaType>();
return true;
}

View File

@ -3536,10 +3536,9 @@ void VulkanDevice::UnbindPipeline(VulkanPipeline* pl)
void VulkanDevice::InvalidateCachedState()
{
DebugAssert(!m_current_render_pass);
m_dirty_flags = ALL_DIRTY_STATE |
((m_current_render_pass_flags & GPUPipeline::ColorFeedbackLoop) ? DIRTY_FLAG_INPUT_ATTACHMENT : 0);
m_current_render_pass = VK_NULL_HANDLE;
m_current_pipeline = nullptr;
}
s32 VulkanDevice::IsRenderTargetBoundIndex(const GPUTexture* tex) const

View File

@ -108,7 +108,9 @@ VulkanPipeline::VulkanPipeline(VkPipeline pipeline, Layout layout, u8 vertices_p
VulkanPipeline::~VulkanPipeline()
{
VulkanDevice::GetInstance().DeferPipelineDestruction(m_pipeline);
VulkanDevice& dev = VulkanDevice::GetInstance();
dev.UnbindPipeline(this);
dev.DeferPipelineDestruction(m_pipeline);
}
#ifdef ENABLE_GPU_OBJECT_NAMES