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

deque::clear() uses undefined behaviour #171

Closed
gleb-cloudius opened this issue Nov 9, 2020 · 2 comments
Closed

deque::clear() uses undefined behaviour #171

gleb-cloudius opened this issue Nov 9, 2020 · 2 comments

Comments

@gleb-cloudius
Copy link

This code:

#include <boost/container/deque.hpp>
int main() {
  boost::container::deque<int> x;
  x.clear();
}

compiled with clang and ubsan clang++ -fsanitize=undefined fails with:

/usr/include/boost/container/deque.hpp:1763:63: runtime error: applying non-zero offset 8 to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/include/boost/container/deque.hpp:1763:63 in 
@nyh
Copy link

nyh commented Nov 9, 2020

I can reproduce this with clang 10.0.0.1, Boost 1.69.0 (on Fedora 32).
It appears that when the container is empty, clear() takes a null pointer + 1 as the beginning of a loop (a loop which will do nothing because its end is a null pointer as well...), but such arithmetic with null pointer is considered "undefined behavior" in C++.

@igaztanaga
Copy link
Member

Many thanks for the report!

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

3 participants