refactor: Avoid UB in SpanReader::ignore

Currently std::span::subspan is called without checking the size first.

This is UB, unless the std lib is hardened.

With a hardened stdlib, the program aborts:

> include/c++/v1/span:512: libc++ Hardening assertion __offset <= size()
> failed: span<T>::subspan(offset, count): offset out of range

Fix the UB and the abort by using the implementation from DataStream,
which throws when hitting end-of-data.

This commit should not change any behavior, because the UB is currently
unreachable. Also, the newly added throw should properly be caught by
any code that calls any streams function.
This commit is contained in:
MarcoFalke
2026-02-02 18:38:58 +01:00
parent fa20bc2ec2
commit fabd4d2e2e

View File

@@ -117,6 +117,9 @@ public:
void ignore(size_t n)
{
if (n > m_data.size()) {
throw std::ios_base::failure("SpanReader::ignore(): end of data");
}
m_data = m_data.subspan(n);
}
};