InText head = (InText)malloc(sizeof(InText)); // 錯誤
head->Text = (char*)malloc(10*sizeof(char)); // 錯誤
InText 是 Node1* 指針類型,sizeof(InText) 返回指針大小(4/8 字節),而非結構體大小。導致分配內存不足,訪問越界。head->Text 定義為 char*,但代碼寫成 (char)malloc(...) 強轉為 char 而非 char*。InText head = (InText)malloc(sizeof(Node1)); // 分配結構體大小
head->Text = (char*)malloc(10 * sizeof(char)); // 正確指針類型
Debug 模式下內存佈局較寬鬆,越界可能暫時不崩潰;Release 優化後內存緊湊,越界立即觸發崩潰。VC6 編輯器對非標準代碼容錯較高。