Vitaly Buka | 46520a4d | 2018-03-07 00:14:12 +0000 | [diff] [blame] | 1 | // RUN: %clangxx_msan -O0 -g %s -o %t && not %run %t |
| 2 | |
| 3 | #include <assert.h> |
| 4 | #include <locale.h> |
| 5 | #include <sanitizer/msan_interface.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <wchar.h> |
| 8 | |
| 9 | int main(void) { |
| 10 | wchar_t q[10]; |
| 11 | size_t n = wcsxfrm(q, L"abcdef", sizeof(q) / sizeof(wchar_t)); |
| 12 | assert(n < sizeof(q)); |
| 13 | __msan_check_mem_is_initialized(q, (n + 1) * sizeof(wchar_t)); |
| 14 | |
| 15 | locale_t loc = newlocale(LC_ALL_MASK, "", (locale_t)0); |
| 16 | |
| 17 | __msan_poison(&q, sizeof(q)); |
| 18 | n = wcsxfrm_l(q, L"qwerty", sizeof(q) / sizeof(wchar_t), loc); |
| 19 | assert(n < sizeof(q)); |
| 20 | __msan_check_mem_is_initialized(q, (n + 1) * sizeof(wchar_t)); |
| 21 | |
| 22 | q[0] = 'A'; |
| 23 | q[1] = '\x00'; |
| 24 | __msan_poison(&q, sizeof(q)); |
| 25 | wcsxfrm(NULL, q, 0); |
| 26 | |
| 27 | // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value |
Fangrui Song | d21b3d3 | 2019-08-02 06:07:05 +0000 | [diff] [blame] | 28 | // CHECK: in main {{.*}}wcsxfrm.cpp:25 |
Vitaly Buka | 46520a4d | 2018-03-07 00:14:12 +0000 | [diff] [blame] | 29 | return 0; |
| 30 | } |