vim-patch:8.2.2309: 0o777 not recognized as octal

Problem:    0o777 not recognized as octal.
Solution:   Use vim_isodigit(). (Ken Takata, closes vim/vim#7633, closes vim/vim#7631)
c37b655443

:scriptversion is N/A.
This commit is contained in:
Sean Dewar 2021-06-03 02:45:36 +01:00
parent 90a4cf92d2
commit 26733dd488
No known key found for this signature in database
GPG Key ID: 08CC2C83AD41B581
2 changed files with 12 additions and 4 deletions

View File

@ -169,6 +169,14 @@ static inline bool ascii_isbdigit(int c)
return (c == '0' || c == '1');
}
/// Checks if `c` is an octal digit, that is, 0-7.
///
/// @see {ascii_isdigit}
static inline bool ascii_isodigit(int c)
{
return (c >= '0' && c <= '7');
}
/// Checks if `c` is a white-space character, that is,
/// one of \f, \n, \r, \t, \v.
///

View File

@ -1463,7 +1463,7 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
if (!STRING_ENDED(ptr + 2)
&& ptr[0] == '0'
&& (ptr[1] == 'o' || ptr[1] == 'O')
&& ascii_isbdigit(ptr[2])) {
&& ascii_isodigit(ptr[2])) {
ptr += 2;
}
goto vim_str2nr_oct;
@ -1499,14 +1499,14 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
if ((what & STR2NR_OOCT)
&& !STRING_ENDED(ptr + 2)
&& (pre == 'O' || pre == 'o')
&& ascii_isbdigit(ptr[2])) {
&& ascii_isodigit(ptr[2])) {
ptr += 2;
goto vim_str2nr_oct;
}
// Detect old octal format: 0 followed by octal digits.
pre = 0;
if (!(what & STR2NR_OCT)
|| !('0' <= ptr[1] && ptr[1] <= '7')) {
|| !ascii_isodigit(ptr[1])) {
goto vim_str2nr_dec;
}
for (int i = 2; !STRING_ENDED(ptr + i) && ascii_isdigit(ptr[i]); i++) {
@ -1552,7 +1552,7 @@ vim_str2nr_bin:
PARSE_NUMBER(2, (*ptr == '0' || *ptr == '1'), (*ptr - '0'));
goto vim_str2nr_proceed;
vim_str2nr_oct:
PARSE_NUMBER(8, ('0' <= *ptr && *ptr <= '7'), (*ptr - '0'));
PARSE_NUMBER(8, (ascii_isodigit(*ptr)), (*ptr - '0'));
goto vim_str2nr_proceed;
vim_str2nr_dec:
PARSE_NUMBER(10, (ascii_isdigit(*ptr)), (*ptr - '0'));