@@ -185,10 +185,6 @@ pub enum Argument {
185185 /// Number of decimal places to display for numbers.
186186 ///
187187 /// This is only applicable for numeric types.
188- ///
189- /// The precision cannot be equal to or greater than the maximum number
190- /// of digits for the type. If it is, it will be set to the maximum
191- /// number of digits minus one.
192188 Precision ( u8 ) ,
193189
194190 /// Truncate the output at the end when the specified maximum number of characters
@@ -294,14 +290,14 @@ macro_rules! impl_log_for_unsigned_integer {
294290 // decimal point + one leading zero
295291 _ => precision + 2 ,
296292 } ;
297- // Determines if the value will be truncated or not.
298- let overflow = required > length;
293+ // Determines whether the value will be truncated or not.
294+ let is_truncated = required > length;
299295 // Cap the number of digits to write to the buffer length.
300- let written = min( MAX_DIGITS - offset, length) ;
296+ let digits_to_write = min( MAX_DIGITS - offset, length) ;
301297
302298 // SAFETY: the length of both `digits` and `buffer` arrays are guaranteed
303- // to be within bounds and the `written ` value is capped to the length of
304- // the `buffer`.
299+ // to be within bounds and the `digits_to_write ` value is capped to the
300+ // length of the `buffer`.
305301 unsafe {
306302 let source = digits. as_ptr( ) . add( offset) ;
307303 let ptr = buffer. as_mut_ptr( ) ;
@@ -312,20 +308,20 @@ macro_rules! impl_log_for_unsigned_integer {
312308 syscalls:: sol_memcpy_(
313309 ptr as * mut _,
314310 source as * const _,
315- written as u64 ,
311+ digits_to_write as u64 ,
316312 ) ;
317313 #[ cfg( not( target_os = "solana" ) ) ]
318- copy_nonoverlapping( source, ptr, written ) ;
314+ copy_nonoverlapping( source, ptr, digits_to_write ) ;
319315 }
320316 // If padding is needed to satisfy the precision, add leading zeros
321317 // and a decimal point.
322- else if precision >= written {
318+ else if precision >= digits_to_write {
323319 // Prefix.
324320 ( ptr as * mut u8 ) . write( b'0' ) ;
325321
326322 if length > 2 {
327323 ( ptr. add( 1 ) as * mut u8 ) . write( b'.' ) ;
328- let padding = min( length - 2 , precision - written ) ;
324+ let padding = min( length - 2 , precision - digits_to_write ) ;
329325
330326 // Precision padding.
331327 #[ cfg( target_os = "solana" ) ]
@@ -341,7 +337,7 @@ macro_rules! impl_log_for_unsigned_integer {
341337
342338 // If there is still space, copy (part of) the number.
343339 if current < length {
344- let remaining = min( written , length - current) ;
340+ let remaining = min( digits_to_write , length - current) ;
345341
346342 // Number part.
347343 #[ cfg( target_os = "solana" ) ]
@@ -358,7 +354,7 @@ macro_rules! impl_log_for_unsigned_integer {
358354 // No padding is needed, calculate the integer and fractional
359355 // parts and add a decimal point.
360356 else {
361- let integer_part = written - precision;
357+ let integer_part = digits_to_write - precision;
362358
363359 // Integer part of the number.
364360 #[ cfg( target_os = "solana" ) ]
@@ -398,8 +394,10 @@ macro_rules! impl_log_for_unsigned_integer {
398394 let written = min( required, length) ;
399395
400396 // There might not have been space.
401- if overflow {
402- // SAFETY: `written` is capped to the length of the buffer.
397+ if is_truncated {
398+ // SAFETY: `written` is capped to the length of the buffer and
399+ // the required length (`required` is always greater than zero);
400+ // `buffer` is guaranteed to have a length of at least 1.
403401 unsafe {
404402 buffer. get_unchecked_mut( written - 1 ) . write( TRUNCATED ) ;
405403 }
0 commit comments