skarupke / flat_hash_map

A very fast hashtable
1.69k stars 186 forks source link

Bug in flat_hash_map.hpp #39

Open ammaraslam10 opened 3 years ago

ammaraslam10 commented 3 years ago

image

Worked fine in debug mode..

NRUB commented 3 years ago

This bug is related to x86. It is indeed crashing, in my case after 1024 allocations as it calls: emplace -> emplace_new_key -> grow -> rehash -> emplace -> emplace_new_key -> grow -> rehash -> emplace and there on line /*line 581*/ for (; current_entry->distance_from_desired >= distance_from_desired; ++current_entry, ++distance_from_desired) it throws read access violation on current_entry.

Tested under VS Community 2019 (16.8.3) /std::c++latest as well as /std:c++17, debug, no optimizations.

SSCCE:

#include <memory>
#include "flat_hash_map.hpp"

class F {
public:
    double a;
};

int main () {
    ska::flat_hash_map<int, std::shared_ptr<F>> map;
    for (int i = 0; i < 250000; ++i) {
        map.emplace(i, std::make_shared<F>());
    }
    return 0;
}