Skip to content

Commit a857520

Browse files
jgautier-anssifabienfl-orc
authored andcommitted
OrcLib: Buffer: fix index check in zero()
1 parent 682e5e9 commit a857520

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/OrcLib/Buffer.h

+16-6
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ class BufferSpan
5252
_T* get(ULONG idx = 0) const
5353
{
5454
if (idx >= m_Elts)
55-
throw Exception(Severity::Fatal, E_INVALIDARG, L"Invalid index acces into BufferExView"sv);
55+
throw Exception(Severity::Fatal, E_INVALIDARG, L"Invalid index access into BufferExView"sv);
5656
return &m_Ptr[idx];
5757
}
5858
const _T& operator[](ULONG idx) const
5959
{
6060
if (idx >= m_Elts)
61-
throw Exception(Severity::Fatal, E_INVALIDARG, L"Invalid index acces into BufferExView"sv);
61+
throw Exception(Severity::Fatal, E_INVALIDARG, L"Invalid index access into BufferExView"sv);
6262
return m_Ptr[idx];
6363
}
6464

@@ -80,6 +80,16 @@ class BufferSpan
8080
return reinterpret_cast<_T_as*>(ptr) + nth;
8181
}
8282

83+
void zero(_In_ const std::optional<ULONG> pos = std::nullopt, _In_ std::optional<ULONG> Elts = std::nullopt)
84+
{
85+
auto size_ = size();
86+
auto position = pos.value_or(0LU);
87+
if (position >= size_)
88+
return;
89+
auto elements = Elts.value_or(size_ - position);
90+
ZeroMemory(get(position), std::min(size_ - position, elements) * sizeof(_T));
91+
}
92+
8393
private:
8494
_T* m_Ptr;
8595
ULONG m_Elts;
@@ -567,9 +577,9 @@ class Buffer
567577
{
568578
auto size_ = size();
569579
auto position = pos.value_or(0LU);
570-
auto elements = Elts.value_or(size_ - position);
571-
if (pos >= size_)
580+
if (position >= size_)
572581
return;
582+
auto elements = Elts.value_or(size_ - position);
573583
ZeroMemory(get(position), std::min(size_ - position, elements) * sizeof(_T));
574584
}
575585

@@ -711,15 +721,15 @@ class Buffer
711721
_T* get_raw(ULONG index = 0) const
712722
{
713723
return std::visit(
714-
[index](auto&& arg) -> auto { return arg.get(index); }, m_store);
724+
[index](auto&& arg) -> auto{ return arg.get(index); }, m_store);
715725
}
716726

717727
explicit operator _T*(void) const { return get(); }
718728

719729
bool owns(void) const
720730
{
721731
return std::visit(
722-
[](auto&& arg) -> auto { return arg.owns(); }, m_store);
732+
[](auto&& arg) -> auto{ return arg.owns(); }, m_store);
723733
}
724734

725735
template <typename _TT>

0 commit comments

Comments
 (0)