[msan] Fix fcvt interceptor.

fcvt() result can be heap-allocated and must be unpoisoned.

llvm-svn: 215106
This commit is contained in:
Evgeniy Stepanov 2014-08-07 12:45:55 +00:00
parent a3d4dc9eb4
commit 37e069c2ac
2 changed files with 19 additions and 0 deletions

View File

@ -577,6 +577,7 @@ INTERCEPTOR(char *, fcvt, double x, int a, int *b, int *c) {
if (!__msan_has_dynamic_component()) {
__msan_unpoison(b, sizeof(*b));
__msan_unpoison(c, sizeof(*c));
if (res) __msan_unpoison(res, REAL(strlen)(res) + 1);
}
return res;
}

View File

@ -2064,8 +2064,26 @@ TEST(MemorySanitizer, fcvt) {
char *str = fcvt(12345.6789, 10, &a, &b);
EXPECT_NOT_POISONED(a);
EXPECT_NOT_POISONED(b);
ASSERT_NE(nullptr, str);
EXPECT_NOT_POISONED(str[0]);
ASSERT_NE(0U, strlen(str));
}
TEST(MemorySanitizer, fcvt_long) {
int a, b;
break_optimization(&a);
break_optimization(&b);
EXPECT_POISONED(a);
EXPECT_POISONED(b);
char *str = fcvt(111111112345.6789, 10, &a, &b);
EXPECT_NOT_POISONED(a);
EXPECT_NOT_POISONED(b);
ASSERT_NE(nullptr, str);
EXPECT_NOT_POISONED(str[0]);
ASSERT_NE(0U, strlen(str));
}
TEST(MemorySanitizer, memchr) {
char x[10];
break_optimization(x);