Misc: Fix a bunch of code analysis warnings

Some of which were even actual errors.
This commit is contained in:
Stenzek
2024-08-02 23:56:06 +10:00
parent 4eb3b2a9a7
commit 3a83c4265c
30 changed files with 93 additions and 78 deletions

View File

@ -90,7 +90,7 @@ public:
ALWAYS_INLINE BinarySpanReader& operator>>(s64& val) { val = ReadT<s64>(); return *this; }
ALWAYS_INLINE BinarySpanReader& operator>>(u64& val) { val = ReadT<u64>(); return *this; }
ALWAYS_INLINE BinarySpanReader& operator>>(float& val) { val = ReadT<float>(); return *this; }
ALWAYS_INLINE BinarySpanReader& operator>>(std::string_view val) { val = ReadCString(); return *this; }
ALWAYS_INLINE BinarySpanReader& operator>>(std::string_view& val) { val = ReadCString(); return *this; }
// clang-format on
template<typename T>
@ -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_view& val) { val = ReadCString(); return *this; }
// clang-format on
template<typename T>

View File

@ -505,7 +505,7 @@ std::string Path::Canonicalize(std::string_view path)
{
// current directory, so it can be skipped, unless it's the only component
if (components.size() == 1)
new_components.push_back(std::move(component));
new_components.push_back(component);
}
else if (component == "..")
{
@ -513,12 +513,12 @@ std::string Path::Canonicalize(std::string_view path)
if (!new_components.empty())
new_components.pop_back();
else
new_components.push_back(std::move(component));
new_components.push_back(component);
}
else
{
// anything else, preserve
new_components.push_back(std::move(component));
new_components.push_back(component);
}
}

View File

@ -233,11 +233,11 @@ ALWAYS_INLINE_RELEASE void Log::FormatLogMessageAndPrintW(const char* channelNam
wmessage_buflen =
MultiByteToWideChar(CP_UTF8, 0, buffer.data(), static_cast<int>(buffer.size()), wmessage_buf, wmessage_buflen);
if (wmessage_buflen <= 0)
return;
wmessage_buf[wmessage_buflen] = '\0';
callback(std::wstring_view(wmessage_buf, wmessage_buflen));
if (wmessage_buflen > 0) [[likely]]
{
wmessage_buf[wmessage_buflen] = '\0';
callback(std::wstring_view(wmessage_buf, wmessage_buflen));
}
if (wmessage_buf != wbuf)
std::free(wmessage_buf);

View File

@ -67,12 +67,12 @@ std::string MemMap::GetFileMappingName(const char* prefix)
void* MemMap::CreateSharedMemory(const char* name, size_t size, Error* error)
{
const HANDLE mapping =
static_cast<void*>(CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, static_cast<DWORD>(size >> 32),
static_cast<DWORD>(size), StringUtil::UTF8StringToWideString(name).c_str()));
CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, static_cast<DWORD>(size >> 32),
static_cast<DWORD>(size), StringUtil::UTF8StringToWideString(name).c_str());
if (!mapping)
Error::SetWin32(error, "CreateFileMappingW() failed: ", GetLastError());
return mapping;
return static_cast<void*>(mapping);
}
void MemMap::DestroySharedMemory(void* ptr)

View File

@ -248,10 +248,12 @@ void SmallStringBase::append_vsprintf(const char* format, va_list ap)
va_copy(ap_copy, ap);
const int ret = std::vsnprintf(buffer, buffer_size, format, ap_copy);
va_end(ap_copy);
if (ret < 0 || ((u32)ret >= (buffer_size - 1)))
if (ret < 0 || (static_cast<u32>(ret) >= (buffer_size - 1)))
{
buffer_size *= 2;
buffer = heap_buffer = reinterpret_cast<char*>(std::realloc(heap_buffer, buffer_size));
if (!buffer) [[unlikely]]
Panic("Memory allocation failed.");
continue;
}
@ -303,7 +305,7 @@ void SmallStringBase::prepend_vsprintf(const char* format, va_list ArgPtr)
// We have a 1KB byte buffer on the stack here. If this is too little, we'll grow it via the heap,
// but 1KB should be enough for most strings.
char stack_buffer[1024];
char* heap_buffer = NULL;
char* heap_buffer = nullptr;
char* buffer = stack_buffer;
u32 buffer_size = static_cast<u32>(std::size(stack_buffer));
u32 written;
@ -315,6 +317,8 @@ void SmallStringBase::prepend_vsprintf(const char* format, va_list ArgPtr)
{
buffer_size *= 2;
buffer = heap_buffer = reinterpret_cast<char*>(std::realloc(heap_buffer, buffer_size));
if (!buffer) [[unlikely]]
Panic("Memory allocation failed.");
continue;
}