Segmentation fault after insertions/lookups/deletions
shachaf opened this issue · 0 comments
shachaf commented
I was testing this library and I ran into a segmentation fault. Here's a program that reproduces it:
$ cat alex-test.cc
#include <stdio.h>
#include "ALEX/src/core/alex_map.h"
int main(int argc, char **argv) {
alex::AlexMap<uint64_t, uint64_t> map;
FILE *f = fopen("alex-test-input.txt", "r");
while (1) {
char buf[100];
char *line = fgets(buf, sizeof buf, f);
if (!line) break;
uint64_t key;
if (line[0] == 'a') {
sscanf(line, "a %lu", &key);
printf("assign %lu\n", key);
map[key] = 0;
} else if (line[0] == 'd') {
sscanf(line, "d %lu", &key);
auto it = map.find(key);
if (!it.is_end()) {
printf("delete %lu\n", key);
map.erase(it);
} else {
printf("!found %lu\n", key);
}
}
}
return 0;
}
$ clang++ -g alex-test.cc -o build/alex-test -march=haswell && ./build/alex-test > /dev/null
Segmentation fault
Here's a stack trace:
#0 0x000000000040a456 in alex::Alex<unsigned long, unsigned long, alex::AlexCompare, std::allocator<std::pair<unsigned long, unsigned long> >, false>::expand_root (
this=0x7fffffffdb10, expand_left=true) at ./ALEX/src/core/alex.h:1454
#1 0x00000000004081f8 in alex::Alex<unsigned long, unsigned long, alex::AlexCompare, std::allocator<std::pair<unsigned long, unsigned long> >, false>::insert (this=0x7fffffffdb10,
key=@0x7fffffffda80: 9178834004329713693, payload=@0x7fffffffd9d8: 0)
at ./ALEX/src/core/alex.h:1117
#2 0x000000000040327d in alex::AlexMap<unsigned long, unsigned long, alex::AlexCompare, std::allocator<std::pair<unsigned long, unsigned long> > >::operator[] (
this=0x7fffffffdb10, key=@0x7fffffffda80: 9178834004329713693)
at ./ALEX/src/core/alex_map.h:128
#3 0x0000000000401640 in main (argc=1, argv=0x7fffffffdce8) at alex-test.cc:18
Here's the test input: https://slbkbs.org/tmp/alex-test-input.txt