mattreecebentley / plf_hive

plf::hive is a fork of plf::colony to match the current C++ standards proposal.
https://plflib.org/colony.htm
zlib License
71 stars 7 forks source link

rbegin/rend segfault when given an empty hive #9

Closed Quuxplusone closed 2 years ago

Quuxplusone commented 2 years ago
#include "plf_hive.h"
#include <cassert>

int main() {
    plf::hive<int> h;
    bool success = (h.rbegin().base() == h.end());
    assert(success);
}

This program hits an assertion inside the implementation of plf::hive; and then if you remove the assertion with NDEBUG, it just segfaults.

$ clang++ -std=c++20 test.cpp ; ./a.out
Assertion failed: (group_pointer != NULL), function operator++, file ./plf_hive.h, line 318.
Abort trap: 6
$ clang++ -std=c++20 -DNDEBUG test.cpp ; ./a.out
Segmentation fault: 11
mattreecebentley commented 2 years ago

Adds some needless NULL checking for a use-case that shouldn't happen in real code, but implemented in beta.

On 23/04/2022 4:42 am, Quuxplusone wrote:

|#include "plf_hive.h" #include int main() { plf::hive h; bool success = (h.rbegin().base() == h.end()); assert(success); }|