5

我想在使用内存消毒剂时FD_ZERO清除误报。FD_SET清除它有点容易:

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

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

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

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

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

4

1 回答 1

2

根据Memory Sanitizer 邮件列表中的 Konstantin Serebryany 所述,没有预处理器宏。应该使用__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
...
于 2016-02-27T18:10:06.133 回答