From a79af6d365dab86ed5a0bbe6c02a91d45d6b4d10 Mon Sep 17 00:00:00 2001 From: csd4ni3l Date: Sun, 19 Apr 2026 18:17:05 +0200 Subject: [PATCH] Fix toupper_table_loc not returning the correct type of ptr --- src/lib.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 95d700c..96f7b8b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,6 +37,8 @@ static TOUPPER_TABLE: [i32; 384] = { table }; +static mut TOUPPER_TABLE_PTR: *const i32 = core::ptr::null(); + #[unsafe(no_mangle)] extern "C" fn write(fd: i32, buf: *const u8, count: usize) -> isize { unsafe { syscall3(WRITE, fd as isize, buf as isize, count as isize) } @@ -624,8 +626,11 @@ unsafe extern "C" fn strrchr(s: *const u8, ch: u8) -> *const u8 { } #[unsafe(no_mangle)] -unsafe extern "C" fn toupper(char: i32) -> i32 { - (char as u8).to_ascii_uppercase() as i32 +unsafe extern "C" fn toupper(ch: i32) -> i32 { + if ch == -1 { + return -1; + } + (ch as u8).to_ascii_uppercase() as i32 } #[unsafe(no_mangle)] @@ -638,8 +643,13 @@ extern "C" fn system(cmd: *const u8) -> i32 { 0 } #[unsafe(no_mangle)] -extern "C" fn __ctype_toupper_loc() -> *const u8 { - TOUPPER_TABLE.as_ptr() as *const u8 +extern "C" fn __ctype_toupper_loc() -> *const *const i32 { + unsafe { + if TOUPPER_TABLE_PTR.is_null() { + TOUPPER_TABLE_PTR = TOUPPER_TABLE.as_ptr(); + } + core::ptr::addr_of!(TOUPPER_TABLE_PTR) + } } #[unsafe(no_mangle)]