c - 如何确定何时使用 -fsanitize=memory?

标签 c macros c-preprocessor msan

我想在使用内存清理程序时清除 FD_ZEROFD_SET 上的误报。清除它有点容易:

#include <sanitizer/msan_interface.h>
...

__msan_unpoison(&readfds, sizeof(readfds));
__msan_unpoison(&writefds, sizeof(writefds));

但是,我不知道如何检测何时使用内存 sanitizer 。也就是说,检测何时在命令行上指定了 -fsanitize=memory。预处理器似乎没有帮助:

$ clang -dM -E -fsanitize=memory - </dev/null | egrep -i 'memory|sanitize|msan'
$

如何确定何时使用 -fsanitize=memory

最佳答案

根据 Konstantin Serebryany 在 Memory Sanitizer mailing list 上的说法, 没有预处理器宏。 __has_feature(memory_sanitizer)应该使用:

#if defined(__has_feature)
#  if __has_feature(memory_sanitizer)
#    define MEMORY_SANITIZER 1
#  endif
#endif
...

#ifdef MEMORY_SANITIZER
#  include <sanitizer/msan_interface.h>
#endif
...

#ifdef MEMORY_SANITIZER
__msan_unpoison(&readfds, sizeof(readfds));
__msan_unpoison(&writefds, sizeof(writefds));
#endif
...

关于c - 如何确定何时使用 -fsanitize=memory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35665226/

相关文章:

c - 为什么 malloc 中的内存不归零?

c - 未找到从头文件链接到的头文件。

c++ - 在#define 中打印变量名

c-preprocessor - 连接预处理器定义以形成字符串

c++ - 字符串的值不同,但打印它们显示相同的值

c++ - 需要一种简单的方法来在 html 中显示 word 文档

C宏给出编译时错误

c++ - 在源代码中表示大数字以提高可读性?

c++ - 吸氧剂,Eclox : Functions autocomplete not working with decorating macros

C编程: Calling a function with macros