Skip to content

Commit 22583d4

Browse files
authored
CoPilot code review feedback (#403)
1 parent 558b8a1 commit 22583d4

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

Audio/WaveBankReader.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
604604

605605
if (m_data.dwFlags & BANKDATA::TYPE_STREAMING)
606606
{
607-
if (m_data.dwAlignment < ALIGNMENT_DVD)
607+
if ((m_data.dwAlignment < ALIGNMENT_DVD) || (m_data.dwAlignment > ALIGNMENT_MAX))
608608
return E_FAIL;
609609
if (m_data.dwAlignment % DVD_SECTOR_SIZE)
610610
return E_FAIL;
@@ -655,7 +655,7 @@ HRESULT WaveBankReader::Impl::Open(const wchar_t* szFileName) noexcept(false)
655655
expectedSize = uint64_t(m_data.dwEntryCount) * m_data.dwEntryNameElementSize;
656656
if (expectedSize > UINT32_MAX)
657657
{
658-
return E_FAIL;
658+
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
659659
}
660660

661661
if (namesBytes >= static_cast<DWORD>(expectedSize))
@@ -1185,7 +1185,9 @@ HRESULT WaveBankReader::Impl::GetMetadata(uint32_t index, Metadata& metadata) co
11851185
{
11861186
const uint64_t offset = uint64_t(metadata.offsetBytes) + uint64_t(m_header.Segments[HEADER::SEGIDX_ENTRYWAVEDATA].dwOffset);
11871187
if (offset > UINT32_MAX)
1188+
{
11881189
return HRESULT_FROM_WIN32(ERROR_ARITHMETIC_OVERFLOW);
1190+
}
11891191

11901192
metadata.offsetBytes = static_cast<uint32_t>(offset);
11911193
}

Src/BinaryReader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#pragma once
1212

13+
#include <cstdint>
1314
#include <memory>
1415
#include <exception>
1516
#include <stdexcept>
@@ -45,7 +46,7 @@ namespace DirectX
4546
{
4647
static_assert(std::is_standard_layout<T>::value, "Can only read plain-old-data types");
4748

48-
uint64_t byteCount = uint64_t(sizeof(T)) * uint64_t(elementCount);
49+
const uint64_t byteCount = uint64_t(sizeof(T)) * uint64_t(elementCount);
4950
if (byteCount > UINT32_MAX)
5051
throw std::overflow_error("ReadArray");
5152

0 commit comments

Comments
 (0)