Skip to content

Commit 1a75632

Browse files
mikhailramalhoyuxuanchen1997
authored andcommitted
[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
1 parent 2c6b6cc commit 1a75632

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

libc/src/__support/HashTable/randomness.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ LIBC_INLINE uint64_t next_random_seed() {
3636
entropy[1] = reinterpret_cast<uint64_t>(&state);
3737
#if defined(LIBC_HASHTABLE_USE_GETRANDOM)
3838
int errno_backup = libc_errno;
39-
ssize_t count = sizeof(entropy);
39+
size_t count = sizeof(entropy);
4040
uint8_t *buffer = reinterpret_cast<uint8_t *>(entropy);
4141
while (count > 0) {
4242
ssize_t len = getrandom(buffer, count, 0);

libc/src/__support/threads/thread.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ struct alignas(STACK_ALIGNMENT) ThreadAttributes {
102102
// exits. It will clean up the thread resources once the thread
103103
// exits.
104104
cpp::Atomic<uint32_t> detach_state;
105-
void *stack; // Pointer to the thread stack
106-
unsigned long long stacksize; // Size of the stack
107-
unsigned long long guardsize; // Guard size on stack
108-
uintptr_t tls; // Address to the thread TLS memory
109-
uintptr_t tls_size; // The size of area pointed to by |tls|.
105+
void *stack; // Pointer to the thread stack
106+
size_t stacksize; // Size of the stack
107+
size_t guardsize; // Guard size on stack
108+
uintptr_t tls; // Address to the thread TLS memory
109+
uintptr_t tls_size; // The size of area pointed to by |tls|.
110110
unsigned char owned_stack; // Indicates if the thread owns this stack memory
111111
pid_t tid;
112112
ThreadStyle style;

libc/src/stdio/fopencookie.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ FileIOResult CookieFile::cookie_write(File *f, const void *data, size_t size) {
4343
auto cookie_file = reinterpret_cast<CookieFile *>(f);
4444
if (cookie_file->ops.write == nullptr)
4545
return 0;
46-
return cookie_file->ops.write(cookie_file->cookie,
47-
reinterpret_cast<const char *>(data), size);
46+
return static_cast<size_t>(cookie_file->ops.write(
47+
cookie_file->cookie, reinterpret_cast<const char *>(data), size));
4848
}
4949

5050
FileIOResult CookieFile::cookie_read(File *f, void *data, size_t size) {
5151
auto cookie_file = reinterpret_cast<CookieFile *>(f);
5252
if (cookie_file->ops.read == nullptr)
5353
return 0;
54-
return cookie_file->ops.read(cookie_file->cookie,
55-
reinterpret_cast<char *>(data), size);
54+
return static_cast<size_t>(cookie_file->ops.read(
55+
cookie_file->cookie, reinterpret_cast<char *>(data), size));
5656
}
5757

5858
ErrorOr<off_t> CookieFile::cookie_seek(File *f, off_t offset, int whence) {

libc/src/sys/auxv/linux/getauxval.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static void initialize_auxv_once(void) {
155155

156156
static AuxEntry read_entry(int fd) {
157157
AuxEntry buf;
158-
ssize_t size = sizeof(AuxEntry);
158+
size_t size = sizeof(AuxEntry);
159159
char *ptr = reinterpret_cast<char *>(&buf);
160160
while (size > 0) {
161161
ssize_t ret = read(fd, ptr, size);

libc/src/sys/stat/linux/kernel_statx.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ LIBC_INLINE int statx(int dirfd, const char *__restrict path, int flags,
8080
return -ret;
8181

8282
statbuf->st_dev = MKDEV(xbuf.stx_dev_major, xbuf.stx_dev_minor);
83-
statbuf->st_ino = xbuf.stx_ino;
83+
statbuf->st_ino = static_cast<decltype(statbuf->st_ino)>(xbuf.stx_ino);
8484
statbuf->st_mode = xbuf.stx_mode;
8585
statbuf->st_nlink = xbuf.stx_nlink;
8686
statbuf->st_uid = xbuf.stx_uid;
@@ -94,7 +94,8 @@ LIBC_INLINE int statx(int dirfd, const char *__restrict path, int flags,
9494
statbuf->st_ctim.tv_sec = xbuf.stx_ctime.tv_sec;
9595
statbuf->st_ctim.tv_nsec = xbuf.stx_ctime.tv_nsec;
9696
statbuf->st_blksize = xbuf.stx_blksize;
97-
statbuf->st_blocks = xbuf.stx_blocks;
97+
statbuf->st_blocks =
98+
static_cast<decltype(statbuf->st_blocks)>(xbuf.stx_blocks);
9899

99100
return 0;
100101
}

0 commit comments

Comments
 (0)