-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
default constructed cursor_type
of range_sequence
has nullptr for boost::container::stable_vector<T>
#214
Comments
Note that the null pointer dereference here is not an issue of flux, but instead that the iterators of the container type I use being unsafe. It would have been trivial to add null check for the iterator type and have minimal performance impact. But still, this is an issue that the user could encounter when using |
cursor_type
of range_sequence
is nullptr for boost::container::stable_vector<T>
cursor_type
of range_sequence
has nullptr for boost::container::stable_vector<T>
Flux requires that cursors of multipass sequences are default constructible in order to support "delayed initialisation" -- i.e. default constructing a cursor and only later setting it to a valid value. However, it is not required that a default constructed cursor represents a valid position for any particular sequence. For things like For example, Flux provides the Originally I did consider whether it would be better to not require default constructibility for multipass cursors, and instead use |
(Also, FYI, Flux has |
flux::distance(seq, from, to)
requires two cursors. I was adapting flux in a function that returns the index of a element and I lazily wroteflux::distance(seq, {}, cursor)
in the hope that the sequence access function would treat the default constructed cursor as pointing to the first element of the sequence:Turns out this immediately triggers ASan:
AddressSanitizer: access-violation on unknown address 0x000000000000
. I had to write this instead:flux::distance(seq, decay_copy(seq).first(), cursor)
decay_copy
becauseauto{X}
still isn't supported by MSVC as of today which is 11/2024The behavior is inconsistent with contiguous sequence:
The cursor type of contiguous sequences is
index_t
(it was set tostd::ptrdiff_t
in my case), and default constructedindex_t
is0
, which means pointing to the first element.I guess the problem is that a
nullptr
iterator has no information about which range it belongs to. So either the cursor needs to become an optional type (default constructed cursor consistently means "nothing"), or there needs to be a special path (if the cursor type is an iterator wrapper) to seek to the first position when the iterator is nullptr (default constructed cursor consistently means the first element).Or the two could be combined: a default constructed cursor is nullopt, and sequence access functions would fallback to the first element if it's nullopt (default constructed cursor consistently means "nothing", the "from" cursor becomes an optional parameter).
Introducing an optional type could have performance impact. So that's also a thing to consider.
The text was updated successfully, but these errors were encountered: