Skip to content

[MSan] Fix minor issues in testcases #144073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2025
Merged

[MSan] Fix minor issues in testcases #144073

merged 1 commit into from
Jun 14, 2025

Conversation

Camsyn
Copy link
Contributor

@Camsyn Camsyn commented Jun 13, 2025

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.

@llvmbot
Copy link
Member

llvmbot commented Jun 13, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Kunqiu Chen (Camsyn)

Changes

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.

Full diff: https://github.com/llvm/llvm-project/pull/144073.diff

2 Files Affected:

  • (modified) compiler-rt/test/msan/ifaddrs.cpp (+1-1)
  • (modified) compiler-rt/test/msan/qsort.cpp (+1-1)
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;
 

Copy link

github-actions bot commented Jun 13, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

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.
Copy link
Contributor

@fmayer fmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Camsyn Camsyn merged commit 2796c41 into llvm:main Jun 14, 2025
7 checks passed
@Camsyn Camsyn deleted the msan-test branch June 14, 2025 10:04
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants