Index: compiler-rt/lib/msan/msan_interceptors.cc =================================================================== --- compiler-rt/lib/msan/msan_interceptors.cc +++ compiler-rt/lib/msan/msan_interceptors.cc @@ -527,7 +527,8 @@ return res; } -INTERCEPTOR(int, mbrtowc, wchar_t *dest, const char *src, SIZE_T n, void *ps) { +INTERCEPTOR(SIZE_T, mbrtowc, wchar_t *dest, const char *src, SIZE_T n, + void *ps) { ENSURE_MSAN_INITED(); SIZE_T res = REAL(mbrtowc)(dest, src, n, ps); if (res != (SIZE_T)-1 && dest) __msan_unpoison(dest, sizeof(wchar_t)); Index: compiler-rt/lib/msan/tests/msan_test.cc =================================================================== --- compiler-rt/lib/msan/tests/msan_test.cc +++ compiler-rt/lib/msan/tests/msan_test.cc @@ -2118,13 +2118,15 @@ } TEST(MemorySanitizer, mbrtowc) { - const char *x = "abc"; - wchar_t wx; - mbstate_t mbs; - memset(&mbs, 0, sizeof(mbs)); - int res = mbrtowc(&wx, x, 3, &mbs); - EXPECT_GT(res, 0); - EXPECT_NOT_POISONED(wx); + mbstate_t mbs = {}; + + wchar_t wc; + size_t res = mbrtowc(&wc, "\377", 1, &mbs); + EXPECT_EQ(res, -1ULL); + + res = mbrtowc(&wc, "abc", 3, &mbs); + EXPECT_GT(res, 0ULL); + EXPECT_NOT_POISONED(wc); } TEST(MemorySanitizer, wcsftime) {