From c4d667c6bf61a82805b48339889de3aa36328d42 Mon Sep 17 00:00:00 2001 From: auronandace Date: Wed, 11 Mar 2026 11:02:53 +0000 Subject: [PATCH] make some cast lossless in macro in wchar --- src/header/wchar/mod.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/header/wchar/mod.rs b/src/header/wchar/mod.rs index ff21b4eebc..08edbf3374 100644 --- a/src/header/wchar/mod.rs +++ b/src/header/wchar/mod.rs @@ -875,9 +875,27 @@ macro_rules! strtou_impl { { let new = result.checked_mul(base as $type).and_then(|result| { if $negative { - result.checked_sub(digit as $type) + #[cfg(target_arch = "x86")] + { + result.checked_sub( + $type::try_from(digit).expect("single digit never overflows"), + ) + } + #[cfg(not(target_arch = "x86"))] + { + result.checked_sub($type::from(digit)) + } } else { - result.checked_add(digit as $type) + #[cfg(target_arch = "x86")] + { + result.checked_add( + $type::try_from(digit).expect("single digit never overflows"), + ) + } + #[cfg(not(target_arch = "x86"))] + { + result.checked_add($type::from(digit)) + } } }); result = match new {