From 3c9c7ade8d811c3e250bdc4ff43f5adb5c95909c Mon Sep 17 00:00:00 2001 From: Skgland Date: Fri, 27 Mar 2026 22:00:54 +0100 Subject: [PATCH] use checked_add to prevent silent overflow --- src/machine/machine_state.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/machine/machine_state.rs b/src/machine/machine_state.rs index 024b31b6..3744da34 100644 --- a/src/machine/machine_state.rs +++ b/src/machine/machine_state.rs @@ -548,7 +548,8 @@ impl MachineState { return true; } - self.cwil.global_count += 1; + // use strict_add once msrv is >= 1.91.0 + self.cwil.global_count = self.cwil.global_count.checked_add(1).unwrap(); if let Some(&(ref limit, block)) = self.cwil.limits.last() { if self.cwil.local_count == *limit { @@ -1127,7 +1128,8 @@ impl CWIL { } pub(crate) fn add_limit(&mut self, mut limit: u128, block: usize) -> u128 { - limit += &self.local_count; + // use strict_add once msrv is >= 1.91.0 + limit = limit.checked_add(self.local_count).unwrap(); match self.limits.last() { Some((ref inner_limit, _)) if *inner_limit <= limit => {} -- 2.54.0