C++ std::map. Crash

325
09 июля 2017, 13:56

При каких условия может произойти Segmentation fault при проверки контейнера на пустоту(empty)? Или поиск по койнтейнеру? Если учесть что в этот контейнер никто не пишет из другого потока...

Clang 4.0

Лог 1

#0  0x0000555558582d12 in std::less<unsigned int>::operator() (this=0x7fff7ec34868, __x=@0x656f5f6515a0: <error reading variable>, __y=@0x7fffffffd494: 38) at /usr/include/c++/6/bits/stl_function.h:386
#1  0x00005555595784e1 in std::_Rb_tree<unsigned int, std::pair<unsigned int const, FactionState>, std::_Select1st<std::pair<unsigned int const, FactionState> >, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, FactionState> > >::_M_lower_bound (this=0x7fff7ec34868, __x=0x656f5f651580, __y=0x7fff7ec34870, __k=@0x7fffffffd494: 38) at /usr/include/c++/6/bits/stl_tree.h:1670
#2  0x00005555595777c7 in std::_Rb_tree<unsigned int, std::pair<unsigned int const, FactionState>, std::_Select1st<std::pair<unsigned int const, FactionState> >, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, FactionState> > >::find (this=0x7fff7ec34868, __k=@0x7fffffffd494: 38) at /usr/include/c++/6/bits/stl_tree.h:2334
#3  0x0000555559576cf5 in std::map<unsigned int, FactionState, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, FactionState> > >::find (this=0x7fff7ec34868, __x=@0x7fffffffd494: 38) at /usr/include/c++/6/bits/stl_map.h:1105

Лог 2

#0  0x0000555559cf87c5 in std::_Deque_iterator<unsigned char, unsigned char&, unsigned char*>::_M_set_node (this=0x7fff8b7fd220, __new_node=0x81ff0efa3dd8) at /usr/include/c++/6/bits/stl_deque.h:255
#1  0x0000555559d03500 in std::_Deque_iterator<unsigned char, unsigned char&, unsigned char*>::operator+= (this=0x7fff8b7fd220, __n=0) at /usr/include/c++/6/bits/stl_deque.h:217
#2  0x0000555559cf86b3 in std::_Deque_iterator<unsigned char, unsigned char&, unsigned char*>::operator+ (this=0x7fff8b7fd3f0, __n=0) at /usr/include/c++/6/bits/stl_deque.h:228
#3  0x0000555559ce7ebe in std::deque<unsigned char, std::allocator<unsigned char> >::_M_erase (this=0x7fff8f0417b0, __position=0 '\000') at /usr/include/c++/6/bits/deque.tcc:235
#4  0x0000555559cd60e0 in std::deque<unsigned char, std::allocator<unsigned char> >::erase (this=0x7fff8f0417b0, __position=0 '\000') at /usr/include/c++/6/bits/stl_deque.h:1748

Лог 3

#0  0x00005555595783d4 in std::_Rb_tree<unsigned int, std::pair<unsigned int const, FactionState>, std::_Select1st<std::pair<unsigned int const, FactionState> >, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, FactionState> > >::_S_right (__x=0xc650bdc0ba50ba0) at /usr/include/c++/6/bits/stl_tree.h:701
#1  0x0000555559577698 in std::_Rb_tree<unsigned int, std::pair<unsigned int const, FactionState>, std::_Select1st<std::pair<unsigned int const, FactionState> >, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, FactionState> > >::_M_erase (this=0x7fff8f45fdd8, __x=0xc650bdc0ba50ba0) at /usr/include/c++/6/bits/stl_tree.h:1638
#2  0x00005555595776ab in std::_Rb_tree<unsigned int, std::pair<unsigned int const, FactionState>, std::_Select1st<std::pair<unsigned int const, FactionState> >, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, FactionState> > >::_M_erase (this=0x7fff8f45fdd8, __x=0x7fff1d9c056a) at /usr/include/c++/6/bits/stl_tree.h:1638
#3  0x0000555559cc5d19 in std::_Rb_tree<unsigned int, std::pair<unsigned int const, FactionState>, std::_Select1st<std::pair<unsigned int const, FactionState> >, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, FactionState> > >::~_Rb_tree (this=0x7fff8f45fdd8, __in_chrg=<optimized out>) at /usr/include/c++/6/bits/stl_tree.h:873
#4  0x0000555559cc06ca in std::map<unsigned int, FactionState, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, FactionState> > >::~map (this=0x7fff8f45fdd8, __in_chrg=<optimized out>) at /usr/include/c++/6/bits/stl_map.h:96
#5  0x0000555559cc0785 in ReputationMgr::~ReputationMgr (this=0x7fff8f45fdd0, __in_chrg=<optimized out>) at 

Лог 4 (не мап, но всё же)

#0  0x000055555a2c55f8 in std::vector<VMAP::MeshTriangle, std::allocator<VMAP::MeshTriangle> >::end (this=0x59fc0f98) at /usr/include/c++/6/bits/stl_vector.h:576
#1  0x000055555a2c2afc in std::vector<VMAP::MeshTriangle, std::allocator<VMAP::MeshTriangle> >::empty (this=0x59fc0f98) at /usr/include/c++/6/bits/stl_vector.h:745
#2  0x000055555a2c0cd0 in VMAP::GroupModel::IntersectRay (this=0x59fc0f60, ray=..., distance=@0x7fff8a7fa6cc: 50, stopAtFirstHit=false) at Models/WorldModel.cpp:393
#3  0x000055555a2c2183 in VMAP::WModelRayCallBack::operator() (this=0x7fff8a7fa680, ray=..., entry=0, distance=@0x7fff8a7fa6cc: 50, pStopAtFirstHit=false) at WorldModel.cpp:449
Answer 1

Причин может быть очень много самых разных.

Из своего опыта сходу могу назвать такие:

  1. К моменту обращения к функции empty уже выполнен деструктор (или что примерно то же самое - освобождение/выделение памяти).
  2. Раз уж речь идет о thread'ах, то испортить map можно не только обращением к этому map'у, но и другими обращениями.

Очень рекомендую утилиту valgrind для отладки.

Answer 2

Если учесть что в этот контейнер никто не пишет из другого потока...

Чтение по несуществующему ключу создаёт этот ключ и добавляет дефаултное значение для него. Так что не факт, что никто не пишет.

READ ALSO
void* в структуре

void* в структуре

Здравствуйте помогите новичку, дело в том что нужно записывать в данную структуру методы, а после вызывать

314
Галерея лучше чем lightgallery? [требует правки]

Галерея лучше чем lightgallery? [требует правки]

Есть ли что еще более лучшее и совершеннее, чем JQuery плагин для просмотра изображений Light Gallery?

340
Мигающий header при скроле

Мигающий header при скроле

Решил сделать прилипающий header при скроле, при этом столкнулся с неприятным багомКогда происходит скрол header начинает мигать

351
MySQL: Сложение строк

MySQL: Сложение строк

Понадобилось сложение строки одного столбца в зависимости от датыВ итоге написал такое:

399