Skip to content

Commit 79c65ff

Browse files
authored
Fix CodeQL warnings in OpenEXR module (#549)
1 parent d8e9d5b commit 79c65ff

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Auxiliary/DirectXTexEXR.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@
4545
#pragma warning(disable : 4244 4996)
4646
#include <ImfRgbaFile.h>
4747
#include <ImfIO.h>
48+
49+
// https://openexr.com/en/latest/PortingGuide.html
50+
#include <OpenEXRConfig.h>
4851
#pragma warning(pop)
4952

53+
#define COMBINED_OPENEXR_VERSION ((10000*OPENEXR_VERSION_MAJOR) + (100*OPENEXR_VERSION_MINOR) + OPENEXR_VERSION_PATCH)
54+
5055
#ifdef __clang__
5156
#pragma clang diagnostic pop
5257
#endif
@@ -148,6 +153,13 @@ namespace
148153
SetLastError(0);
149154
}
150155

156+
#if COMBINED_OPENEXR_VERSION >= 30300
157+
int64_t read(void *buf, uint64_t sz, uint64_t offset) override
158+
{
159+
return Imf::IStream::read(buf, sz, offset);
160+
}
161+
#endif
162+
151163
private:
152164
HANDLE m_hFile;
153165
LONGLONG m_EOF;
@@ -220,7 +232,7 @@ HRESULT DirectX::GetMetadataFromEXRFile(const wchar_t* szFile, TexMetadata& meta
220232
const int nameLength = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, nullptr, 0, nullptr, nullptr);
221233
if (nameLength > 0)
222234
{
223-
fileName.resize(nameLength);
235+
fileName.resize(static_cast<size_t>(nameLength));
224236
const int result = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, fileName.data(), nameLength, nullptr, nullptr);
225237
if (result <= 0)
226238
{
@@ -338,7 +350,7 @@ HRESULT DirectX::LoadFromEXRFile(const wchar_t* szFile, TexMetadata* metadata, S
338350
const int nameLength = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, nullptr, 0, nullptr, nullptr);
339351
if (nameLength > 0)
340352
{
341-
fileName.resize(nameLength);
353+
fileName.resize(static_cast<size_t>(nameLength));
342354
const int result = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, fileName.data(), nameLength, nullptr, nullptr);
343355
if (result <= 0)
344356
{
@@ -487,7 +499,7 @@ HRESULT DirectX::SaveToEXRFile(const Image& image, const wchar_t* szFile)
487499
const int nameLength = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, nullptr, 0, nullptr, nullptr);
488500
if (nameLength > 0)
489501
{
490-
fileName.resize(nameLength);
502+
fileName.resize(static_cast<size_t>(nameLength));
491503
const int result = WideCharToMultiByte(CP_UTF8, 0, szFile, -1, fileName.data(), nameLength, nullptr, nullptr);
492504
if (result <= 0)
493505
{

0 commit comments

Comments
 (0)