2010-05-20 48 views
0

我有一個應用程序正試圖填充一對。應用程序崩潰無處不在。訪問衝突在std ::對

的崩潰轉儲WinDbg的分析表明:

PRIMARY_PROBLEM_CLASS:INVALID_POINTER_READ

DEFAULT_BUCKET_ID:INVALID_POINTER_READ

STACK_TEXT:
0389f1dc EPFilter32! std::vector<std::pair<unsigned int,unsigned int>,std::allocator<std::pair<unsigned int,unsigned int> > >::size+0xc

INVALID_POINTER_READ_c0000005_Test.DLL! std::vector_std::pair_unsigned_int, unsigned_int_,std::allocator_std::pair_unsigned_int,unsigned_int_____::size

以下是在失敗的代碼的代碼管理單元:

for (unsigned i1 = 0; i1 < size1; ++i1) 
{ 
    for (unsigned i2 = 0; i2 < size2; ++i2) 
    { 
     const branch_info& b1 = en1.m_branches[i1]; //Exception here :crash 
     const branch_info& b2 = en2.m_branches[i2]; 
    } 
} 

其中branch_infostd::pair<unsigned int,unsigned int>en1.m_branches[i1]取我一雙價值。

+0

這裏沒有足夠的信息來診斷問題......你可以在崩潰的線路上多發一些代碼嗎? – 2010-05-20 06:27:52

+0

因此,崩潰似乎是突然發生的?正如在有時for循環完成,但其他時間不是因爲崩潰? – Robb 2010-05-20 06:41:31

回答

4

可能i1索引超出了en1.m_branches向量的範圍。

爲什麼不在循環條件中使用en1.m_branches.size()?這將確保您在正確的邊界內使用索引。

+0

是的,但那不一致 – 2010-05-20 06:33:03

+1

@sameer不符合什麼? – pmr 2010-05-20 11:59:08