Skip to content

Commit 6dec338

Browse files
[sanitizer] Fix few size types in memprof (llvm#119114)
Fix type in a few related Min() calls. Follow up to llvm#116957. Co-authored-by: Stefan Schulze Frielinghaus <[email protected]>
1 parent 8669028 commit 6dec338

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

compiler-rt/lib/asan/asan_interceptors.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ INTERCEPTOR(char*, strncat, char *to, const char *from, usize size) {
535535
AsanInitFromRtl();
536536
if (flags()->replace_str) {
537537
uptr from_length = MaybeRealStrnlen(from, size);
538-
uptr copy_length = Min(size, from_length + 1);
538+
uptr copy_length = Min<uptr>(size, from_length + 1);
539539
ASAN_READ_RANGE(ctx, from, copy_length);
540540
uptr to_length = internal_strlen(to);
541541
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) {
622622
ASAN_INTERCEPTOR_ENTER(ctx, strncpy);
623623
AsanInitFromRtl();
624624
if (flags()->replace_str) {
625-
uptr from_size = Min(size, MaybeRealStrnlen(from, size) + 1);
625+
uptr from_size = Min<uptr>(size, MaybeRealStrnlen(from, size) + 1);
626626
CHECK_RANGES_OVERLAP("strncpy", to, from_size, from, from_size);
627627
ASAN_READ_RANGE(ctx, from, from_size);
628628
ASAN_WRITE_RANGE(ctx, to, size);

compiler-rt/lib/memprof/memprof_interceptors.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ INTERCEPTOR(char *, strcat, char *to, const char *from) {
185185
return REAL(strcat)(to, from);
186186
}
187187

188-
INTERCEPTOR(char *, strncat, char *to, const char *from, uptr size) {
188+
INTERCEPTOR(char *, strncat, char *to, const char *from, usize size) {
189189
void *ctx;
190190
MEMPROF_INTERCEPTOR_ENTER(ctx, strncat);
191191
ENSURE_MEMPROF_INITED();
192192
uptr from_length = MaybeRealStrnlen(from, size);
193-
uptr copy_length = Min(size, from_length + 1);
193+
uptr copy_length = Min<uptr>(size, from_length + 1);
194194
MEMPROF_READ_RANGE(from, copy_length);
195195
uptr to_length = internal_strlen(to);
196196
MEMPROF_READ_STRING(to, to_length);
@@ -239,11 +239,11 @@ INTERCEPTOR(char *, __strdup, const char *s) {
239239
return reinterpret_cast<char *>(new_mem);
240240
}
241241

242-
INTERCEPTOR(char *, strncpy, char *to, const char *from, uptr size) {
242+
INTERCEPTOR(char *, strncpy, char *to, const char *from, usize size) {
243243
void *ctx;
244244
MEMPROF_INTERCEPTOR_ENTER(ctx, strncpy);
245245
ENSURE_MEMPROF_INITED();
246-
uptr from_size = Min(size, MaybeRealStrnlen(from, size) + 1);
246+
uptr from_size = Min<uptr>(size, MaybeRealStrnlen(from, size) + 1);
247247
MEMPROF_READ_RANGE(from, from_size);
248248
MEMPROF_WRITE_RANGE(to, size);
249249
return REAL(strncpy)(to, from, size);

compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ extern const short *_tolower_tab_;
347347
uptr copy_length = internal_strnlen(s, size); \
348348
char *new_mem = (char *)WRAP(malloc)(copy_length + 1); \
349349
if (common_flags()->intercept_strndup) { \
350-
COMMON_INTERCEPTOR_READ_STRING(ctx, s, Min(size, copy_length + 1)); \
350+
COMMON_INTERCEPTOR_READ_STRING(ctx, s, Min<uptr>(size, copy_length + 1)); \
351351
} \
352352
if (new_mem) { \
353353
COMMON_INTERCEPTOR_COPY_STRING(ctx, new_mem, s, copy_length); \

0 commit comments

Comments
 (0)