Skip to content

Commit 788ef5d

Browse files
committed
Add precision cap
1 parent 7ccb7ba commit 788ef5d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

sdk/log/crate/src/logger.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ pub enum Argument {
175175
/// Number of decimal places to display for numbers.
176176
///
177177
/// This is only applicable for numeric types.
178+
///
179+
/// The precision cannot be equal to or greater than the maximum number
180+
/// of digits for the type. If it is, it will be set to the maximum
181+
/// number of digits minus one.
178182
Precision(u8),
179183

180184
/// Truncate the output at the end when the specified maximum number of characters
@@ -262,7 +266,13 @@ macro_rules! impl_log_for_unsigned_integer {
262266
.iter()
263267
.find(|arg| matches!(arg, Argument::Precision(_)))
264268
{
265-
*p as usize
269+
// Precision cannot be equal to or greater than the maximum number
270+
// of digits for the type..
271+
if (*p as usize) >= MAX_DIGITS {
272+
MAX_DIGITS - 1
273+
} else {
274+
*p as usize
275+
}
266276
} else {
267277
0
268278
};

0 commit comments

Comments
 (0)