[MSan] Fix minor issues in testcases (#144073)

Previously,
1. ifaddrs.cpp : mistake `size_t (xxx)` as `sizeof (xxx)`, resulting in 
inadequate checks.
2. qsort.cpp : mistake `kSize2` as `kSize1`, resulting in an unexpected
buffer overlow issue.
This commit is contained in:
Kunqiu Chen
2025-06-14 14:59:36 +08:00
committed by GitHub
parent 07fa6d1d90
commit 2796c41249
2 changed files with 6 additions and 6 deletions

View File

@@ -18,7 +18,7 @@
#define CHECK_AND_PUSH(addr, size) \
if (addr) { \
assert(-1 == __msan_test_shadow(addr, sizeof(size))); \
assert(-1 == __msan_test_shadow(addr, (size_t)(size))); \
ranges.push_back(std::make_pair((void *)addr, (size_t)size)); \
}
@@ -35,7 +35,7 @@ int main(int argc, char *argv[]) {
assert(res == 0);
assert(-1 == __msan_test_shadow(&ifas, sizeof(ifaddrs *)));
std::vector<std::pair<void *, size_t> > ranges;
std::vector<std::pair<void *, size_t>> ranges;
ifaddrs *p = ifas;
while (p) {
CHECK_AND_PUSH(p, sizeof(ifaddrs));

View File

@@ -52,7 +52,7 @@ int compar1(const void *a, const void *b) {
// kind of random
for (int i = 0; i < kSize2; ++i)
p[i] = i * 2 + (i % 3 - 1) * 3;
qsort(p, kSize1, sizeof(long), compar2);
qsort(p, kSize2, sizeof(long), compar2);
__msan_check_mem_is_initialized(p, sizeof(long) * kSize2);
delete[] p;