From 91bf0a073951aa1ca4c357967ed5aff891941785 Mon Sep 17 00:00:00 2001 From: "Mikhail R. Gadelha" Date: Sat, 20 Jul 2024 20:12:31 +0200 Subject: [libc] Added static casts to fix implicit conversion warnings in 32-bit systems This patch fixes: randomness.h and getauxval.cpp were passing ssize_t as size_t kernel_statx.h was assigning an uint64_t to uintptr_t fopencookie.cpp was trying to create a FileIOResult using ssize_t but the constructor expected a size_t thread.h was trying to call free_stack (which takes a size_t) with an unsigned long long. free_stack does the calculations using uintptr_t, so I changed the passing values to size_t --- libc/src/__support/HashTable/randomness.h | 2 +- libc/src/__support/threads/thread.h | 10 +++++----- libc/src/stdio/fopencookie.cpp | 8 ++++---- libc/src/sys/auxv/linux/getauxval.cpp | 2 +- libc/src/sys/stat/linux/kernel_statx.h | 5 +++-- 5 files changed, 14 insertions(+), 13 deletions(-) (limited to 'libc/src') diff --git a/libc/src/__support/HashTable/randomness.h b/libc/src/__support/HashTable/randomness.h index 06d3e84..244dd41 100644 --- a/libc/src/__support/HashTable/randomness.h +++ b/libc/src/__support/HashTable/randomness.h @@ -36,7 +36,7 @@ LIBC_INLINE uint64_t next_random_seed() { entropy[1] = reinterpret_cast(&state); #if defined(LIBC_HASHTABLE_USE_GETRANDOM) int errno_backup = libc_errno; - ssize_t count = sizeof(entropy); + size_t count = sizeof(entropy); uint8_t *buffer = reinterpret_cast(entropy); while (count > 0) { ssize_t len = getrandom(buffer, count, 0); diff --git a/libc/src/__support/threads/thread.h b/libc/src/__support/threads/thread.h index 1805b6f..9317452 100644 --- a/libc/src/__support/threads/thread.h +++ b/libc/src/__support/threads/thread.h @@ -102,11 +102,11 @@ struct alignas(STACK_ALIGNMENT) ThreadAttributes { // exits. It will clean up the thread resources once the thread // exits. cpp::Atomic detach_state; - void *stack; // Pointer to the thread stack - unsigned long long stacksize; // Size of the stack - unsigned long long guardsize; // Guard size on stack - uintptr_t tls; // Address to the thread TLS memory - uintptr_t tls_size; // The size of area pointed to by |tls|. + void *stack; // Pointer to the thread stack + size_t stacksize; // Size of the stack + size_t guardsize; // Guard size on stack + uintptr_t tls; // Address to the thread TLS memory + uintptr_t tls_size; // The size of area pointed to by |tls|. unsigned char owned_stack; // Indicates if the thread owns this stack memory pid_t tid; ThreadStyle style; diff --git a/libc/src/stdio/fopencookie.cpp b/libc/src/stdio/fopencookie.cpp index 07be9a5..9f5694e 100644 --- a/libc/src/stdio/fopencookie.cpp +++ b/libc/src/stdio/fopencookie.cpp @@ -43,16 +43,16 @@ FileIOResult CookieFile::cookie_write(File *f, const void *data, size_t size) { auto cookie_file = reinterpret_cast(f); if (cookie_file->ops.write == nullptr) return 0; - return cookie_file->ops.write(cookie_file->cookie, - reinterpret_cast(data), size); + return static_cast(cookie_file->ops.write( + cookie_file->cookie, reinterpret_cast(data), size)); } FileIOResult CookieFile::cookie_read(File *f, void *data, size_t size) { auto cookie_file = reinterpret_cast(f); if (cookie_file->ops.read == nullptr) return 0; - return cookie_file->ops.read(cookie_file->cookie, - reinterpret_cast(data), size); + return static_cast(cookie_file->ops.read( + cookie_file->cookie, reinterpret_cast(data), size)); } ErrorOr CookieFile::cookie_seek(File *f, off_t offset, int whence) { diff --git a/libc/src/sys/auxv/linux/getauxval.cpp b/libc/src/sys/auxv/linux/getauxval.cpp index 2ca894d..bfa6b23 100644 --- a/libc/src/sys/auxv/linux/getauxval.cpp +++ b/libc/src/sys/auxv/linux/getauxval.cpp @@ -155,7 +155,7 @@ static void initialize_auxv_once(void) { static AuxEntry read_entry(int fd) { AuxEntry buf; - ssize_t size = sizeof(AuxEntry); + size_t size = sizeof(AuxEntry); char *ptr = reinterpret_cast(&buf); while (size > 0) { ssize_t ret = read(fd, ptr, size); diff --git a/libc/src/sys/stat/linux/kernel_statx.h b/libc/src/sys/stat/linux/kernel_statx.h index f26f0b8..d0e223a 100644 --- a/libc/src/sys/stat/linux/kernel_statx.h +++ b/libc/src/sys/stat/linux/kernel_statx.h @@ -80,7 +80,7 @@ LIBC_INLINE int statx(int dirfd, const char *__restrict path, int flags, return -ret; statbuf->st_dev = MKDEV(xbuf.stx_dev_major, xbuf.stx_dev_minor); - statbuf->st_ino = xbuf.stx_ino; + statbuf->st_ino = static_castst_ino)>(xbuf.stx_ino); statbuf->st_mode = xbuf.stx_mode; statbuf->st_nlink = xbuf.stx_nlink; statbuf->st_uid = xbuf.stx_uid; @@ -94,7 +94,8 @@ LIBC_INLINE int statx(int dirfd, const char *__restrict path, int flags, statbuf->st_ctim.tv_sec = xbuf.stx_ctime.tv_sec; statbuf->st_ctim.tv_nsec = xbuf.stx_ctime.tv_nsec; statbuf->st_blksize = xbuf.stx_blksize; - statbuf->st_blocks = xbuf.stx_blocks; + statbuf->st_blocks = + static_castst_blocks)>(xbuf.stx_blocks); return 0; } -- cgit v1.1