0

对地图执行任何操作时出现分段错误。它的声明如下:

typedef std::map<uint16_t, std::vector<std::pair<std::string, uint16_t> > > bitMap_t;

然后我有一个使用这张地图的私人班级成员

        private:
        bitMap_t m_bitMap;

我使用此地图的代码如下所示

uint16_t i = 1;
uint16_t j = 0;
uint16_t reg = 0;
uint16_t regIndex = 0;
uint8_t regSizeWords = 0;

for (regIndex = 0; regIndex < NUMBER_OF_BIT_REGS; regIndex++) {
    for (i = 1, reg = m_regList[regIndex].address; reg < (m_regList[regIndex].address + REGS_SIZE); reg++, i++) {
        for (j = 0; j < m_regList[regIndex].signalsAndBitMasks.size(); j++) {
            ostringstream signalName;
            signalName << m_regList[regIndex].signalsAndBitMasks[j].first << "." << i;

            m_bitMap[reg].push_back(make_pair(signalName.str(), m_regList[regIndex].signalsAndBitMasks[j].second));
        }
    }
}

我还测试了在所有这些代码之前只做一个 m_bitMap.clear() 并且这也不起作用。所以我猜它与嵌套地图、向量和对或?段错误错误如下所示:

std::less<unsigned short>::operator() at stl_function.h:230 0x805e8da
std::_Rb_tree<unsigned short, std::pair<unsigned short const, std::vector<std::pair<std::string, unsigned short>, std::allocator<std::pair<std::string, unsigned short> > > >, std::_Select1st<std::pair<unsigned short const, std::vector<std::pair<std::string, unsigned short>, std::allocator<std::pair<std::string, unsigned short> > > > >, std::less<unsigned short>, std::allocator<std::pair<unsigned short const, std::vector<std::pair<std::string, unsigned short>, std::allocator<std::pair<std::string, unsigned short> > > > > >::_M_lower_bound() at stl_tree.h:986 0x8063a0f

std::_Rb_tree<unsigned short, std::pair<unsigned short const, std::vector<std::pair<std::string, unsigned short>, std::allocator<std::pair<std::string, unsigned short> > > >, std::_Select1st<std::pair<unsigned short const, std::vector<std::pair<std::string, unsigned short>, std::allocator<std::pair<std::string, unsigned short> > > > >, std::less<unsigned short>, std::allocator<std::pair<unsigned short const, std::vector<std::pair<std::string, unsigned short>, std::allocator<std::pair<std::string, unsigned short> > > > > >::lower_bound() at stl_tree.h:745 0x8063531

std::map<unsigned short, std::vector<std::pair<std::string, unsigned short>, std::allocator<std::pair<std::string, unsigned short> > >, std::less<unsigned short>, std::allocator<std::pair<unsigned short const, std::vector<std::pair<std::string, unsigned short>, std::allocator<std::pair<std::string, unsigned short> > > > > >::lower_bound() at stl_map.h:701 0x806311a

std::map<unsigned short, std::vector<std::pair<std::string, unsigned short>, std::allocator<std::pair<std::string, unsigned short> > >, std::less<unsigned short>, std::allocator<std::pair<unsigned short const, std::vector<std::pair<std::string, unsigned short>, std::allocator<std::pair<std::string, unsigned short> > > > > >::operator[]() at stl_map.h:447 0x8062bc1

srvmgr::MbBitMap::InitBitMap() at mbbitmap.cpp:175 0x80620cc

4

1 回答 1

1

到目前为止,最常见的原因首先是实际上没有地图。

你写地图是private: bitMap_t m_bitMap;,即一个对象的成员。我敢打赌你有一个指向这个对象的指针(MbBitMap?),但由于某种原因,与这个指针无关的std::map是无效的。

于 2013-01-28T15:42:22.790 回答