I'm investigating a dump, caused by an access violation.
On that particular line of code, there is the following line:
if (internal_map.find(uiElemKey) == internal_map.end() ||
internal_map[uiElemKey].find(m_iPID) == internal_map[uiElemKey].end() ||
internal_map[uiElemKey][m_iPID].find(idx) == internal_map[uiElemKey][m_iPID].end()) {
In the watch-window I can see that the amount of entries in internal_map
equals 0.
In my opinion, the access violation might be caused by following reasons:
- As there are no entries in the map, the
find()
method generates an exception. - As the are no entries in the map, the
end()
method generates an exception. - The
find()
method and theend()
method are working fine, but give different results, which leads to the following condition, where an access violation happens.
I think that the access violation can be avoided, using this condition:
if (internal_map.size() == 0 ||
internal_map.find(uiElemKey) == internal_map.end() ||
internal_map[uiElemKey].find(m_iPID) == internal_map[uiElemKey].end() ||
internal_map[uiElemKey][m_iPID].find(idx) == internal_map[uiElemKey][m_iPID].end()) {
Can somebody confirm this is correct and explain which reason is the correct one?
Thanks in advance
P.s. for your information: I'm doing dump analysis, and it's almost impossible to reproduce the mentioned problem, so just trying and see what happens is not an option.
find
on empty map. I suspect your map is corrupted before the call. – Sandiefind
, you might avoid repetitive look-ups. – Sandieempty
can you produce a complete5
line example program that reproduced the error? – Amphitritemutex
) to avoid UB by possibly writing and reading the same variable at the same time. – Sandieinternal_map
, theuiElemKey
, the code)? Does the code overload the hash function for your key type and could the exception be happening there? Does the access violation happen on a read or a write operation? – Confine