gpt4 book ai didi

c++ - UBSan 和 Asan 在 GCC 4.9.2 中的使用

转载 作者:搜寻专家 更新时间:2023-10-31 00:32:17 37 4
gpt4 key购买 nike

我已经使用 -fsanitize=undefined 选项编译了我的应用程序。我现在如何测试我的应用程序是否存在未定义的行为?

另外,我该如何进行牙山检查?我用 -fsanitize=address 编译了我的程序,它崩溃了,输出如下:

==4563==Sanitizer CHECK failed: ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:85 ((allocated < kCallocPoolSize)) != (0) (0, 0)

我在 Ubuntu 15.04 上安装了 GCC 4.9.2。

最佳答案

与静态分析检查不同,此检查将在运行时完成,如以下博客条目所述:GCC Undefined Behavior Sanitizer – ubsan .当它检测到未定义的行为时,它会输出一个运行时错误:

In order to check your program with ubsan, compile and link theprogram with -fsanitize=undefined option. Such instrumented binarieshave to be executed; if ubsan detects any problem, it outputs a“runtime error:” message, and in most cases continues executing theprogram. There is a possibility of making these diagnostic messagesabort — just use the option -fno-sanitize-recover.

我们可以从那里看到一个例子:

int main() {
int i = 23;
i <<= 32;
}

当使用 -fsanitize=undefined 运行时将输出 ( see it live ):

runtime error: shift exponent 32 is too large for 32-bit type 'int'

GCC 在他们的 Options for Debugging Your Program or GCC section 中记录了这个选项它说:

Enable UndefinedBehaviorSanitizer, a fast undefined behavior detector.Various computations are instrumented to detect undefined behavior atruntime.

asan issue this address-sanitizer document给你一个例子和预期的结果。也许你的情况与this gcc bug有关.

关于c++ - UBSan 和 Asan 在 GCC 4.9.2 中的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31805590/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com