Skip to content

Commit 9384aa1

Browse files
committed
Avoid unnecessary u64 cast in int-to-str digit check
bits() is already u64, so `bits as u64` fails clippy unnecessary_cast under -Dwarnings. Assisted-by: Grok:4.6
1 parent 7e788b4 commit 9384aa1

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎crates/vm/src/builtins/int.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,11 @@ pub(crate) fn check_int_to_str_digits(value: &BigInt, vm: &VirtualMachine) -> Py
707707
return Ok(());
708708
}
709709
// Upper bound on decimal digit count: ⌈bits × log10(2)⌉ + 1, with log10(2) ≈ 0.30103.
710-
// Multiply in u64: `bits as usize * 30103` wraps on 32-bit (wasm32) once
711-
// bits ≳ 142_500, which silently accepts over-limit conversions.
712-
let digits_upper = (bits as u64).saturating_mul(30103) / 100_000 + 1;
713-
if digits_upper > limit as u64 {
710+
// Multiply with the u64 bit count: `bits as usize * 30103` wraps on
711+
// 32-bit (wasm32) once bits ≳ 142_500, which silently accepts over-limit
712+
// conversions.
713+
let digits_upper = bits.saturating_mul(30103) / 100_000 + 1;
714+
if digits_upper > u64::try_from(limit).unwrap_or(u64::MAX) {
714715
return Err(vm.new_value_error(format!(
715716
"Exceeds the limit ({limit} digits) for integer string conversion; \
716717
use sys.set_int_max_str_digits() to increase the limit"

0 commit comments

Comments
 (0)