Skip to content

Remove undefined pointer arithmetic from empty buffer iterators #7

Description

@vshalygin

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions