From 4827e548bead8733f1e7b348d10086e89c310714 Mon Sep 17 00:00:00 2001 From: TheUbMunster <66451362+TheUbMunster@users.noreply.github.com> Date: Sat, 22 Jun 2024 19:12:04 -0600 Subject: [PATCH] BinarySpanReaderWriter: Fix off-by-one error (#3230) fix off-by-one error --- src/common/binary_span_reader_writer.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/binary_span_reader_writer.h b/src/common/binary_span_reader_writer.h index 6a21c5aed..7bae91a4a 100644 --- a/src/common/binary_span_reader_writer.h +++ b/src/common/binary_span_reader_writer.h @@ -62,7 +62,7 @@ public: private: ALWAYS_INLINE bool Read(void* buf, size_t size) { - if ((m_pos + size) < m_buf.size()) [[likely]] + if ((m_pos + size) <= m_buf.size()) [[likely]] { std::memcpy(buf, &m_buf[m_pos], size); m_pos += size; @@ -74,7 +74,7 @@ private: ALWAYS_INLINE bool Peek(void* buf, size_t size) { - if ((m_pos + size) < m_buf.size()) [[likely]] + if ((m_pos + size) <= m_buf.size()) [[likely]] { std::memcpy(buf, &m_buf[m_pos], size); return true; @@ -119,7 +119,7 @@ public: private: ALWAYS_INLINE bool Write(void* buf, size_t size) { - if ((m_pos + size) < m_buf.size()) [[likely]] + if ((m_pos + size) <= m_buf.size()) [[likely]] { std::memcpy(&m_buf[m_pos], buf, size); m_pos += size;