Skip to content
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

etl::max_element has undefined behavior if the range is empty #1017

Closed
jonasgampigbmw opened this issue Jan 20, 2025 · 0 comments
Closed

etl::max_element has undefined behavior if the range is empty #1017

jonasgampigbmw opened this issue Jan 20, 2025 · 0 comments

Comments

@jonasgampigbmw
Copy link

If etl::max_element is called with an empty range, i.e. begin == end, it causes undefined behavior. According to https://en.cppreference.com/w/cpp/algorithm/max_element, it should return end instead if the range is empty.

The root cause is that begin is incremented first, which leads to begin pointing to the element after end. Then, the while-loop will execute and begin will be dereferenced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant