This issue was identified during a Codex code review.
buffer, buffer_view, and cbuffer_view calculate their end and reverse iterators using m_buffer + m_size.
For default-constructed empty objects, m_buffer is nullptr and m_size is zero. Even adding zero to a null pointer is not formally defined by the C++ standard. Subtracting two null-backed iterators has the same problem.
Make iterator construction and distance calculation safe for empty buffers and add regression tests for all three buffer types.
This issue was identified during a Codex code review.
buffer,buffer_view, andcbuffer_viewcalculate their end and reverse iterators usingm_buffer + m_size.For default-constructed empty objects,
m_bufferisnullptrandm_sizeis zero. Even adding zero to a null pointer is not formally defined by the C++ standard. Subtracting two null-backed iterators has the same problem.Make iterator construction and distance calculation safe for empty buffers and add regression tests for all three buffer types.