[compiler-rt] [sanitizer] Fix few size types in memprof (PR #119114)

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 7 21:01:17 PST 2024


https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/119114

And a few related Min() calls.

Follow up to #116957.


>From 51892e890795e05409d4bc1c4a3499761df07a6f Mon Sep 17 00:00:00 2001
From: Stefan Schulze Frielinghaus <stefansf at linux.ibm.com>
Date: Sat, 7 Dec 2024 21:01:00 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 compiler-rt/lib/asan/asan_interceptors.cpp                | 4 ++--
 compiler-rt/lib/memprof/memprof_interceptors.cpp          | 8 ++++----
 .../sanitizer_common/sanitizer_common_interceptors.inc    | 2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/compiler-rt/lib/asan/asan_interceptors.cpp b/compiler-rt/lib/asan/asan_interceptors.cpp
index be214f3ebeb6db..e6c95dfb82c320 100644
--- a/compiler-rt/lib/asan/asan_interceptors.cpp
+++ b/compiler-rt/lib/asan/asan_interceptors.cpp
@@ -535,7 +535,7 @@ INTERCEPTOR(char*, strncat, char *to, const char *from, usize size) {
   AsanInitFromRtl();
   if (flags()->replace_str) {
     uptr from_length = MaybeRealStrnlen(from, size);
-    uptr copy_length = Min(size, from_length + 1);
+    uptr copy_length = Min<uptr>(size, from_length + 1);
     ASAN_READ_RANGE(ctx, from, copy_length);
     uptr to_length = internal_strlen(to);
     ASAN_READ_STRING_OF_LEN(ctx, to, to_length, to_length);
@@ -622,7 +622,7 @@ INTERCEPTOR(char*, strncpy, char *to, const char *from, usize size) {
   ASAN_INTERCEPTOR_ENTER(ctx, strncpy);
   AsanInitFromRtl();
   if (flags()->replace_str) {
-    uptr from_size = Min(size, MaybeRealStrnlen(from, size) + 1);
+    uptr from_size = Min<uptr>(size, MaybeRealStrnlen(from, size) + 1);
     CHECK_RANGES_OVERLAP("strncpy", to, from_size, from, from_size);
     ASAN_READ_RANGE(ctx, from, from_size);
     ASAN_WRITE_RANGE(ctx, to, size);
diff --git a/compiler-rt/lib/memprof/memprof_interceptors.cpp b/compiler-rt/lib/memprof/memprof_interceptors.cpp
index 49d8c2a6218345..f4d7fd46e61983 100644
--- a/compiler-rt/lib/memprof/memprof_interceptors.cpp
+++ b/compiler-rt/lib/memprof/memprof_interceptors.cpp
@@ -185,12 +185,12 @@ INTERCEPTOR(char *, strcat, char *to, const char *from) {
   return REAL(strcat)(to, from);
 }
 
-INTERCEPTOR(char *, strncat, char *to, const char *from, uptr size) {
+INTERCEPTOR(char *, strncat, char *to, const char *from, usize size) {
   void *ctx;
   MEMPROF_INTERCEPTOR_ENTER(ctx, strncat);
   ENSURE_MEMPROF_INITED();
   uptr from_length = MaybeRealStrnlen(from, size);
-  uptr copy_length = Min(size, from_length + 1);
+  uptr copy_length = Min<uptr>(size, from_length + 1);
   MEMPROF_READ_RANGE(from, copy_length);
   uptr to_length = internal_strlen(to);
   MEMPROF_READ_STRING(to, to_length);
@@ -239,11 +239,11 @@ INTERCEPTOR(char *, __strdup, const char *s) {
   return reinterpret_cast<char *>(new_mem);
 }
 
-INTERCEPTOR(char *, strncpy, char *to, const char *from, uptr size) {
+INTERCEPTOR(char *, strncpy, char *to, const char *from, usize size) {
   void *ctx;
   MEMPROF_INTERCEPTOR_ENTER(ctx, strncpy);
   ENSURE_MEMPROF_INITED();
-  uptr from_size = Min(size, MaybeRealStrnlen(from, size) + 1);
+  uptr from_size = Min<uptr>(size, MaybeRealStrnlen(from, size) + 1);
   MEMPROF_READ_RANGE(from, from_size);
   MEMPROF_WRITE_RANGE(to, size);
   return REAL(strncpy)(to, from, size);
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index f6b695defce414..99ad3b244d4e2c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -347,7 +347,7 @@ extern const short *_tolower_tab_;
   uptr copy_length = internal_strnlen(s, size);                               \
   char *new_mem = (char *)WRAP(malloc)(copy_length + 1);                      \
   if (common_flags()->intercept_strndup) {                                    \
-    COMMON_INTERCEPTOR_READ_STRING(ctx, s, Min(size, copy_length + 1));       \
+    COMMON_INTERCEPTOR_READ_STRING(ctx, s, Min<uptr>(size, copy_length + 1)); \
   }                                                                           \
   if (new_mem) {                                                              \
     COMMON_INTERCEPTOR_COPY_STRING(ctx, new_mem, s, copy_length);             \



More information about the llvm-commits mailing list