錯誤: allocation-size-too-big
解決清理工具錯誤:allocation-size-too-big
此範例顯示當配置對堆積而言太大時所發現的錯誤。 來自 LLVM 編譯器 rt 測試套件 的範例。
範例
// example1.cpp
// allocation-size-too-big error
#include <stdio.h>
#include <malloc.h>
#include <memory.h>
int x = 1000;
int y = 1000;
__declspec(noinline) void bad_function() {
char* buffer = (char*)malloc(x * y * x * y); //Boom!
memcpy(buffer, buffer + 8, 8);
}
int main(int argc, char **argv) {
bad_function();
return 0;
}
若要建置及測試此範例,請在 Visual Studio 2019 16.9 版或更新版本的 開發人員命令提示字元 中執行下列命令:
cl example1.cpp /fsanitize=address /Zi
devenv /debugexe example1.exe
產生的錯誤
另請參閱
AddressSanitizer 概觀
AddressSanitizer 已知問題
AddressSanitizer 組建和語言參考
AddressSanitizer 執行時間參考
AddressSanitizer 陰影位元組
AddressSanitizer 雲端或分散式測試
AddressSanitizer 偵錯工具整合
AddressSanitizer 錯誤範例
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應