1 // RUN: %clangxx_msan %s -o %t && not %run %t 2>&1 | FileCheck --check-prefix=ON %s
2 // RUN: %clangxx_msan %s -o %t && env MSAN_OPTIONS=intercept_strndup=0 %run %t 2>&1 | FileCheck --check-prefix=OFF --allow-empty %s
4 // When built as C on Linux, strndup is transformed to __strndup.
5 // RUN: %clangxx_msan -O3 -xc %s -o %t && not %run %t 2>&1 | FileCheck --check-prefix=ON %s
7 // UNSUPPORTED: target={{.*windows-msvc.*}}
12 #include <sanitizer/msan_interface.h>
14 int main(int argc
, char **argv
) {
15 char kString
[4] = "abc";
16 __msan_poison(kString
+ 2, 1);
17 char *copy
= strndup(kString
, 4); // BOOM
18 assert(__msan_test_shadow(copy
, 4) == 2); // Poisoning is preserved.
21 // ON: Uninitialized bytes in {{(__)?}}strndup at offset 2 inside [{{.*}}, 4)
22 // ON: MemorySanitizer: use-of-uninitialized-value
23 // ON: #0 {{.*}}main {{.*}}strndup.cpp:[[@LINE-6]]
25 // ON: {{.*}}strndup.cpp:[[@LINE-8]]
26 // OFF-NOT: MemorySanitizer