[問題] stack smashing detected如何解決?

看板C_and_CPP (C/C++)作者時間15年前 (2011/05/11 09:48), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Linux uBuntu 10.04 gcc 4.4.3 問題(Question): 程式跑到一半出現stact smashing detected 被強迫中止 有問題的程式碼大致如下 void myclass::0nIdle(wxIdleEvent& event) { function_a(); // a b 都是myclass的function printf("test2\n"); // 後來加上去的 function_b(); ... } void myclass::function_a(){ 宣告變數 while(mPathgGuiStream->CanRead() == true) { ... } printf("test1\n"); } function_a() 與 function_b() 執行多次後出現問題 於是我加了兩個printf測試 發現程式最後test1有印出來 接著stack smashing detected test2沒有印出來 這樣是指在離開function_a()的時候出現錯誤嗎? 請問有人有類似經驗嗎? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.42.145

05/11 13:24, , 1F
加 -fno-stack-protector 然後用 gdb 看
05/11 13:24, 1F

05/11 13:25, , 2F
另外...是 OnIdle 不是 0nIdle 吧 XD
05/11 13:25, 2F

05/12 09:24, , 3F
謝謝 找到錯誤了 是wxString在call destructor時出現seg
05/12 09:24, 3F
文章代碼(AID): #1DoUhMFQ (C_and_CPP)
文章代碼(AID): #1DoUhMFQ (C_and_CPP)