mattreecebentley / plf_colony

An unordered C++ data container providing fast iteration/insertion/erasure while maintaining pointer/iterator validity to non-erased elements regardless of insertions/erasures. Provides higher-performance than std:: library containers for high-modification scenarios with unordered data.
https://plflib.org/colony.htm
zlib License
398 stars 33 forks source link

get_iterator dereferences a null pointer when using it on a colony that had elements but now is empty #54

Closed Mishura4 closed 2 months ago

Mishura4 commented 2 months ago

Repro: https://godbolt.org/z/Yj8Eqzejb

#include <https://raw.githubusercontent.com/mattreecebentley/plf_colony/master/plf_colony.h>
#include <iostream>

int main() {
    plf::colony<int> foo;
    int bar;

    foo.erase(foo.emplace(5));
    std::cout << "before" << std::endl;
    auto it = foo.get_iterator(&bar);
    std::cout << "after" << std::endl;
    std::cout << (it == foo.end()) << std::endl;
    return 0;
}

Output (clang++ trunk):

Program returned: 139
Program terminated with signal: SIGSEGV
before

Crashes on both clang & msvc, did not test g++

MSVC debugger shows line 3721 as the culprit with current_group was nullptr

mattreecebentley commented 2 months ago

Sorry I misread this. Will take a look later.

mattreecebentley commented 2 months ago

Thanks for spotting this, fixed now!