環境:Xcode、C代碼
問題現象:
build運行,代碼全部執行成功,退出前報錯:
終端運行,退出前報錯:Abort trap: 6
從代碼中篩選出導致錯誤的語句:
fscanf(fp, "%[^\n]\n",aWordInList);
呃...但原因不明...
以 Abort trap: 6 和 fscanf 谷歌 得到:scanf數組超界
嘗試修改 aWordInList[64] => aWordInList[1024]
運行成功!
后對越界數組測試:
循環中加入代碼:
1 if(strlen(aWordInList)>63){ 2 printf("|%s|越界數組=%lu\n",aWordInList,strlen(aWordInList)); 3 getchar(); 4 }
果然找到多個,😓小瞧它了。