I've really tried to put off asking this question because it seems like it should be a simple problem, but here goes. I've been chasing a segfault in a new piece of code. I've included the smallest chunk that demonstrates the issue below. The rest of the code has been working for some time.
class A {
private:
std::map <uint64_t, uint32_t> memberMap;
public:
A();
~A();
void access() {
const uint64_t key = 1;
uint32_t value = 1;
if(memberMap.count(key) == 0) {
memberMap.insert(std::pair<uint64_t, uint32_t>(key, value));
} else if(memberMap[key] < value) {
memberMap[key] = value;
}
}
};
class B : public BsParent {
private:
A handler;
public:
B();
~B();
uint64_t access(Data dat) {
//...
handler.access();
//...
}
};
What I've tried so far...
- You'll notice there are zero explicit pointers.
- I've checked that A() is called.
- The stack trace from gdb (yep, already played with that extensively with no obvious null pointers) pins the blame on stl_tree.h:1157 which defines the pair function. However if I comment out the insert line and the else if block the program still segfaults at another obscure line number in stl_tree.
- I tested the code in access() by making memberMap a local variable in access and calling the code in a loop.
Any thoughts or suggestions on further debugging steps?