[compiler-rt] [MSan] Fix minor issues in testcases (PR #144073)

Kunqiu Chen via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 13 06:02:55 PDT 2025


https://github.com/Camsyn created https://github.com/llvm/llvm-project/pull/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.

>From 081980ae6eb6f4f0b67b6d2e66cf4fcbebd4174c Mon Sep 17 00:00:00 2001
From: Camsyn <camsyn at foxmail.com>
Date: Fri, 13 Jun 2025 20:06:50 +0800
Subject: [PATCH] [MSan] Fix minor issues in testcases

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.
---
 compiler-rt/test/msan/ifaddrs.cpp | 2 +-
 compiler-rt/test/msan/qsort.cpp   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/test/msan/ifaddrs.cpp b/compiler-rt/test/msan/ifaddrs.cpp
index 91730a01f2d8a..2379e8ebb6477 100644
--- a/compiler-rt/test/msan/ifaddrs.cpp
+++ b/compiler-rt/test/msan/ifaddrs.cpp
@@ -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)); \
   }
 
diff --git a/compiler-rt/test/msan/qsort.cpp b/compiler-rt/test/msan/qsort.cpp
index af287ed64357e..93e6845e1ea7a 100644
--- a/compiler-rt/test/msan/qsort.cpp
+++ b/compiler-rt/test/msan/qsort.cpp
@@ -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;
 



More information about the llvm-commits mailing list