我想在使用内存消毒器时清除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 =内存何时正在使用?
最佳答案 根据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
...