[AA] Rename CaptureInfo -> CaptureAnalysis (NFC) (#116842)
[llvm-project.git] / compiler-rt / test / msan / strndup.cpp
blob12d918130f7186eea74e46384e20c63ed584b1a7
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.*}}
9 #include <assert.h>
10 #include <stdlib.h>
11 #include <string.h>
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.
19 free(copy);
20 return 0;
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]]
24 // ON-LABEL: SUMMARY
25 // ON: {{.*}}strndup.cpp:[[@LINE-8]]
26 // OFF-NOT: MemorySanitizer