错误:allocation-size-too-big
地址擦除系统错误:allocation-size-too-big
此示例展示了当分配对堆来说太大时发现的错误。 这是来自 LLVM compiler-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 错误示例