c++ - 如何找到陣列越界錯誤?
我想大声告诉你
我想大声告诉你 2017-06-07 09:24:17
0
2
1000
(gdb) bt
#0  0x000000368d275fd5 in malloc_consolidate () from /lib64/libc.so.6
#1  0x000000368d279c28 in _int_malloc () from /lib64/libc.so.6
#2  0x000000368d27ab1c in malloc () from /lib64/libc.so.6
#3  0x000000368debd09d in operator new(unsigned long) () from /usr/lib64/libstdc++.so.6
#4  0x000000000040fbcd in __gnu_cxx::new_allocator<unsigned char>::allocate (this=0x7ffc7e0136d8, __n=4096)
    at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ext/new_allocator.h:89
#5  0x000000000040f575 in std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_M_allocate (this=0x7ffc7e0136d8, __n=4096)
    at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_vector.h:140
#6  0x000000000040f186 in std::vector<unsigned char, std::allocator<unsigned char> >::_M_allocate_and_copy<unsigned char*> (this=0x7ffc7e0136d8, 
    __n=4096, __first=0x0, __last=0x0) at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_vector.h:963
#7  0x000000000040e7c7 in std::vector<unsigned char, std::allocator<unsigned char> >::reserve (this=0x7ffc7e0136d8, __n=4096)
    at /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/vector.tcc:74
#8  0x00000000004cc616 in ByteBuffer::ByteBuffer (this=0x7ffc7e0136c0) at ../../../../src/shared/./util/ByteBuffer.h:19
#9  0x00000000004cb947 in ReplayMgr::SaveToDB (this=0x23a40d0, pBase=0x57a1160) at ./Replay/ReplayMgr.cpp:95

百度了下可能是某個地方數組越界把不該寫的記憶體寫壞了
請問有沒有什麼好的辦法檢查數組越界的地方具體在哪裡?

我想大声告诉你
我想大声告诉你

全部回覆(2)
女神的闺蜜爱上我

你用 bt 看堆疊有什麼用...

既然程式碼是你寫的,仔細檢查一些文法,這是最直接的方法。下幾個關鍵的斷點,一步一步執行一下,很快就能發現問題所在。

另外,dump法也是解決類似錯誤的有效方法。

phpcn_u1582

瓦爾格林德

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!