我想在使用内存消毒剂时清除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
?
答案 0 :(得分:1)
根据Memory Sanitizer mailing list的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
...