google / emboss

Emboss is a tool for generating code that reads and writes binary data structures.
Apache License 2.0
68 stars 21 forks source link

Array iterators should keep a copy of, not a pointer to, the underlying `ArrayView` #95

Closed reventlov closed 10 months ago

reventlov commented 10 months ago

Keeping a pointer makes it very easy to make the pointer dangle, as in:

auto it = view.array().begin();
// it holds a pointer to the now-dead temporary `array()`

Further, since the equality checks in the iterator use the pointer, code like this walks off the end of the array:

assert(std::equal(view.array().begin(), view.array().end(), other.begin()));