Skip to content

Commit 98d26f2

Browse files
committed
fix possible cross-platform issue that code failing to pass on some tests
1 parent 124b5fe commit 98d26f2

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/uucore/src/lib/features/format/spec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl Spec {
374374
let precision = resolve_asterisk(*precision, &mut args)?.unwrap_or(0);
375375
let i = args.get_i64();
376376

377-
if precision > i32::MAX as usize {
377+
if precision as u64 > i32::MAX as u64 {
378378
return Err(FormatError::InvalidPrecision(precision.to_string()));
379379
}
380380

@@ -397,7 +397,7 @@ impl Spec {
397397
let precision = resolve_asterisk(*precision, &mut args)?.unwrap_or(0);
398398
let i = args.get_u64();
399399

400-
if precision > i32::MAX as usize {
400+
if precision as u64 > i32::MAX as u64 {
401401
return Err(FormatError::InvalidPrecision(precision.to_string()));
402402
}
403403

@@ -423,7 +423,7 @@ impl Spec {
423423
let precision = resolve_asterisk(*precision, &mut args)?.unwrap_or(6);
424424
let f = args.get_f64();
425425

426-
if precision > i32::MAX as usize {
426+
if precision as u64 > i32::MAX as u64 {
427427
return Err(FormatError::InvalidPrecision(precision.to_string()));
428428
}
429429

tests/by-util/test_printf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ fn invalid_precision_fails() {
788788
fn float_invalid_precision_fails() {
789789
// It is invalid to have length of output string greater than i32::MAX
790790
new_ucmd!()
791-
.args(&["%.*f", "9999999999", "0"])
791+
.args(&["%.*f", "2147483648", "0"])
792792
.fails()
793-
.stderr_is("printf: invalid precision: '9999999999'\n");
793+
.stderr_is("printf: invalid precision: '2147483648'\n");
794794
}

0 commit comments

Comments
 (0)