Skip to content

Commit e84de9b

Browse files
committed
uucore: fast_inc: Add a debug_assert for developer convenience
Suggested by our AI overlords.
1 parent 4fe0da4 commit e84de9b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/uucore/src/lib/features/fast_inc.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ pub fn fast_inc(val: &mut [u8], start: &mut usize, end: usize, inc: &[u8]) {
3535

3636
// First loop, add all digits of inc into val.
3737
for inc_pos in (0..inc.len()).rev() {
38+
// The decrement operation would also panic in debug mode, print a message for developer convenience.
39+
debug_assert!(
40+
pos > 0,
41+
"Buffer overflowed, make sure you allocate val with enough headroom."
42+
);
3843
pos -= 1;
3944

4045
let mut new_val = inc[inc_pos] + carry;
@@ -99,6 +104,11 @@ pub fn fast_inc_one(val: &mut [u8], start: &mut usize, end: usize) {
99104
}
100105
}
101106

107+
// The following decrement operation would also panic in debug mode, print a message for developer convenience.
108+
debug_assert!(
109+
*start > 0,
110+
"Buffer overflowed, make sure you allocate val with enough headroom."
111+
);
102112
// The carry propagated so far that a new digit was added.
103113
val[*start - 1] = b'1';
104114
*start -= 1;

0 commit comments

Comments
 (0)