mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
printf: Print special error for invalid octal numbers
(tbh these were always a mistake) See #9035
This commit is contained in:
parent
d6d2c9cd1e
commit
13a9f6b64e
2 changed files with 30 additions and 0 deletions
|
@ -169,6 +169,12 @@ void builtin_printf_state_t::verify_numeric(const wchar_t *s, const wchar_t *end
|
|||
} else {
|
||||
// This isn't entirely fatal - the value should still be printed.
|
||||
this->nonfatal_error(_(L"%ls: value not completely converted (can't convert '%ls')"), s, end);
|
||||
// Warn about octal numbers as they can be confusing.
|
||||
// Do it if the unconverted digit is a valid hex digit,
|
||||
// because it could also be an "0x" -> "0" typo.
|
||||
if (*s == L'0' && iswxdigit(*end)) {
|
||||
this->nonfatal_error(_(L"Hint: a leading '0' without an 'x' indicates an octal number"), s, end);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,3 +95,27 @@ printf '%d\n' 15.1
|
|||
# CHECKERR: 15.1: value not completely converted (can't convert '.1')
|
||||
echo $status
|
||||
# CHECK: 1
|
||||
|
||||
printf '%d\n' 07
|
||||
# CHECK: 7
|
||||
echo $status
|
||||
# CHECK: 0
|
||||
printf '%d\n' 08
|
||||
# CHECK: 0
|
||||
# CHECKERR: 08: value not completely converted (can't convert '8')
|
||||
# CHECKERR: Hint: a leading '0' without an 'x' indicates an octal number
|
||||
echo $status
|
||||
# CHECK: 1
|
||||
|
||||
printf '%d\n' 0f
|
||||
# CHECK: 0
|
||||
# CHECKERR: 0f: value not completely converted (can't convert 'f')
|
||||
# CHECKERR: Hint: a leading '0' without an 'x' indicates an octal number
|
||||
echo $status
|
||||
# CHECK: 1
|
||||
|
||||
printf '%d\n' 0g
|
||||
# CHECK: 0
|
||||
# CHECKERR: 0g: value not completely converted (can't convert 'g')
|
||||
echo $status
|
||||
# CHECK: 1
|
||||
|
|
Loading…
Reference in a new issue