mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 20:17:45 +00:00
printf: fix negative hex argument parsing
This commit is contained in:
parent
ce18e0ab97
commit
5f2374b339
1 changed files with 7 additions and 3 deletions
|
@ -49,9 +49,13 @@ impl FormatArgument {
|
||||||
match self {
|
match self {
|
||||||
Self::SignedInt(n) => Some(*n),
|
Self::SignedInt(n) => Some(*n),
|
||||||
Self::Unparsed(s) => {
|
Self::Unparsed(s) => {
|
||||||
if let Some(s) = s.strip_prefix("0x") {
|
// For hex, we parse `u64` because we do not allow another
|
||||||
i64::from_str_radix(s, 16).ok()
|
// minus sign. We might need to do more precise parsing here.
|
||||||
} else if let Some(s) = s.strip_prefix("0") {
|
if let Some(s) = s.strip_prefix("-0x") {
|
||||||
|
Some(- (u64::from_str_radix(s, 16).ok()? as i64))
|
||||||
|
} else if let Some(s) = s.strip_prefix("0x") {
|
||||||
|
Some(u64::from_str_radix(s, 16).ok()? as i64)
|
||||||
|
} else if s.starts_with("-0") || s.starts_with('0') {
|
||||||
i64::from_str_radix(s, 8).ok()
|
i64::from_str_radix(s, 8).ok()
|
||||||
} else if let Some(s) = s.strip_prefix('\'') {
|
} else if let Some(s) = s.strip_prefix('\'') {
|
||||||
Some(s.chars().next()? as i64)
|
Some(s.chars().next()? as i64)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue