Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CodeQL warnings in OpenEXR module #549

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Auxiliary/DirectXTexEXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@
#pragma warning(disable : 4244 4996)
#include <ImfRgbaFile.h>
#include <ImfIO.h>

// https://openexr.com/en/latest/PortingGuide.html
#include <OpenEXRConfig.h>
#pragma warning(pop)

#define COMBINED_OPENEXR_VERSION ((10000*OPENEXR_VERSION_MAJOR) + (100*OPENEXR_VERSION_MINOR) + OPENEXR_VERSION_PATCH)

#ifdef __clang__
#pragma clang diagnostic pop
#endif
Expand Down Expand Up @@ -148,6 +153,13 @@
SetLastError(0);
}

#if COMBINED_OPENEXR_VERSION >= 30300
int64_t read(void *buf, uint64_t sz, uint64_t offset) override
{
return Imf::IStream::read(buf, sz, offset);
}
#endif

private:
HANDLE m_hFile;
LONGLONG m_EOF;
Expand Down Expand Up @@ -220,7 +232,7 @@
const int nameLength = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, nullptr, 0, nullptr, nullptr);
if (nameLength > 0)
{
fileName.resize(nameLength);
fileName.resize(static_cast<size_t>(nameLength));
const int result = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, fileName.data(), nameLength, nullptr, nullptr);
if (result <= 0)
{
Expand Down Expand Up @@ -338,7 +350,7 @@
const int nameLength = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, nullptr, 0, nullptr, nullptr);
if (nameLength > 0)
{
fileName.resize(nameLength);
fileName.resize(static_cast<size_t>(nameLength));
const int result = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, fileName.data(), nameLength, nullptr, nullptr);
if (result <= 0)
{
Expand Down Expand Up @@ -487,7 +499,7 @@
const int nameLength = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, nullptr, 0, nullptr, nullptr);
if (nameLength > 0)
{
fileName.resize(nameLength);
fileName.resize(static_cast<size_t>(nameLength));
const int result = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, fileName.data(), nameLength, nullptr, nullptr);
if (result <= 0)
{
Expand Down Expand Up @@ -544,7 +556,7 @@
{
const uint64_t bytes = image.width * image.height;

if (bytes > static_cast<uint64_t>(UINT32_MAX))

Check warning on line 559 in Auxiliary/DirectXTexEXR.cpp

View workflow job for this annotation

GitHub Actions / build (windows-2022, x86-Debug-VCPKG, amd64_x86)

Conversion rules for arithmetic operations in the comparison at D:\a\DirectXTex\DirectXTex\Auxiliary\DirectXTexEXR.cpp(557) mean that one branch cannot be executed. Cast '<unknown>' to 'ULONG64' (or similar type of 8 bytes).
{
return /* HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW) */ static_cast<HRESULT>(0x80070216L);
}
Expand Down
Loading