1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #7656 from eduardorittner/main

printf: make negative values wrap around with unsigned/hex format
This commit is contained in:
Sylvestre Ledru 2025-04-10 06:48:50 -04:00 committed by GitHub
commit a89fc48388
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 69 additions and 13 deletions

View file

@ -2,6 +2,8 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore fffffffffffffffc
use uutests::new_ucmd;
use uutests::util::TestScenario;
use uutests::util_name;
@ -791,6 +793,41 @@ fn partial_integer() {
.stderr_is("printf: '42x23': value not completely converted\n");
}
#[test]
fn unsigned_hex_negative_wraparound() {
new_ucmd!()
.args(&["%x", "-0b100"])
.succeeds()
.stdout_only("fffffffffffffffc");
new_ucmd!()
.args(&["%x", "-0100"])
.succeeds()
.stdout_only("ffffffffffffffc0");
new_ucmd!()
.args(&["%x", "-100"])
.succeeds()
.stdout_only("ffffffffffffff9c");
new_ucmd!()
.args(&["%x", "-0x100"])
.succeeds()
.stdout_only("ffffffffffffff00");
new_ucmd!()
.args(&["%x", "-92233720368547758150"])
.fails_with_code(1)
.stdout_is("ffffffffffffffff")
.stderr_is("printf: '-92233720368547758150': Numerical result out of range\n");
new_ucmd!()
.args(&["%u", "-1002233720368547758150"])
.fails_with_code(1)
.stdout_is("18446744073709551615")
.stderr_is("printf: '-1002233720368547758150': Numerical result out of range\n");
}
#[test]
fn test_overflow() {
new_ucmd!()