[問題] heap use after free 問題

看板C_and_CPP作者 (檸檬羊)時間3年前 (2021/03/20 16:39), 3年前編輯推噓1(102)
留言3則, 1人參與, 3年前最新討論串1/2 (看更多)
開發平台(Platform): (Ex: Win10, Linux, ...) Leetcode C++ *[36m問題(Question):*[m 小弟在寫這題 https://leetcode.com/problems/insertion-sort-list/ 我第 9 行如果不先把 cur->next 指定成 nullptr 執行時就會出現 heap-use-after-free 的錯誤 一時腦袋空空想不出來哪裡出錯了... 不曉得是甚摸原因 感謝各位前輩! 程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔) http://codepad.org/hidj7vRl -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.177.3.109 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1616229569.A.043.html ※ 編輯: lemonsheep (180.177.3.109 臺灣), 03/20/2021 16:40:27

03/20 19:04, 3年前 , 1F
第九行是不需要的,主要問題在於...
03/20 19:04, 1F

03/20 19:05, 3年前 , 2F
當 cur 插到前面去時,原本 cur 所在位置的前後關係
03/20 19:05, 2F

03/20 19:06, 3年前 , 3F
也需要處理。
03/20 19:06, 3F
文章代碼(AID): #1WLRJ113 (C_and_CPP)
文章代碼(AID): #1WLRJ113 (C_and_CPP)