Mercurial > vim
comparison src/charset.c @ 20665:6ff992bf4c82 v8.2.0886
patch 8.2.0886: cannot use octal numbers in scriptversion 4
Commit: https://github.com/vim/vim/commit/c17e66c5c0acd5038f1eb3d7b3049b64bb6ea30b
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jun 2 21:38:22 2020 +0200
patch 8.2.0886: cannot use octal numbers in scriptversion 4
Problem: Cannot use octal numbers in scriptversion 4.
Solution: Add the "0o" notation. (Ken Takata, closes https://github.com/vim/vim/issues/5304)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 02 Jun 2020 21:45:03 +0200 |
parents | aadd1cae2ff5 |
children | c4bce986c31a |
comparison
equal
deleted
inserted
replaced
20664:2ee305469487 | 20665:6ff992bf4c82 |
---|---|
1762 * Convert a string into a long and/or unsigned long, taking care of | 1762 * Convert a string into a long and/or unsigned long, taking care of |
1763 * hexadecimal, octal, and binary numbers. Accepts a '-' sign. | 1763 * hexadecimal, octal, and binary numbers. Accepts a '-' sign. |
1764 * If "prep" is not NULL, returns a flag to indicate the type of the number: | 1764 * If "prep" is not NULL, returns a flag to indicate the type of the number: |
1765 * 0 decimal | 1765 * 0 decimal |
1766 * '0' octal | 1766 * '0' octal |
1767 * 'O' octal | |
1768 * 'o' octal | |
1767 * 'B' bin | 1769 * 'B' bin |
1768 * 'b' bin | 1770 * 'b' bin |
1769 * 'X' hex | 1771 * 'X' hex |
1770 * 'x' hex | 1772 * 'x' hex |
1771 * If "len" is not NULL, the length of the number in characters is returned. | 1773 * If "len" is not NULL, the length of the number in characters is returned. |
1781 */ | 1783 */ |
1782 void | 1784 void |
1783 vim_str2nr( | 1785 vim_str2nr( |
1784 char_u *start, | 1786 char_u *start, |
1785 int *prep, // return: type of number 0 = decimal, 'x' | 1787 int *prep, // return: type of number 0 = decimal, 'x' |
1786 // or 'X' is hex, '0' = octal, 'b' or 'B' | 1788 // or 'X' is hex, '0', 'o' or 'O' is octal, |
1787 // is bin | 1789 // 'b' or 'B' is bin |
1788 int *len, // return: detected length of number | 1790 int *len, // return: detected length of number |
1789 int what, // what numbers to recognize | 1791 int what, // what numbers to recognize |
1790 varnumber_T *nptr, // return: signed result | 1792 varnumber_T *nptr, // return: signed result |
1791 uvarnumber_T *unptr, // return: unsigned result | 1793 uvarnumber_T *unptr, // return: unsigned result |
1792 int maxlen, // max length of string to check | 1794 int maxlen, // max length of string to check |
1819 ptr += 2; | 1821 ptr += 2; |
1820 else if ((what & STR2NR_BIN) | 1822 else if ((what & STR2NR_BIN) |
1821 && (pre == 'B' || pre == 'b') && vim_isbdigit(ptr[2]) | 1823 && (pre == 'B' || pre == 'b') && vim_isbdigit(ptr[2]) |
1822 && (maxlen == 0 || maxlen > 2)) | 1824 && (maxlen == 0 || maxlen > 2)) |
1823 // binary | 1825 // binary |
1826 ptr += 2; | |
1827 else if ((what & STR2NR_OOCT) | |
1828 && (pre == 'O' || pre == 'o') && vim_isbdigit(ptr[2]) | |
1829 && (maxlen == 0 || maxlen > 2)) | |
1830 // octal with prefix "0o" | |
1824 ptr += 2; | 1831 ptr += 2; |
1825 else | 1832 else |
1826 { | 1833 { |
1827 // decimal or octal, default is decimal | 1834 // decimal or octal, default is decimal |
1828 pre = 0; | 1835 pre = 0; |
1867 if (n++ == maxlen) | 1874 if (n++ == maxlen) |
1868 break; | 1875 break; |
1869 } | 1876 } |
1870 } | 1877 } |
1871 } | 1878 } |
1872 else if (pre == '0' || ((what & STR2NR_OCT) && (what & STR2NR_FORCE))) | 1879 else if (pre == 'O' || pre == 'o' || |
1880 pre == '0' || ((what & STR2NR_OCT) && (what & STR2NR_FORCE))) | |
1873 { | 1881 { |
1874 // octal | 1882 // octal |
1883 if (pre != 0 && pre != '0') | |
1884 n += 2; // skip over "0o" | |
1875 while ('0' <= *ptr && *ptr <= '7') | 1885 while ('0' <= *ptr && *ptr <= '7') |
1876 { | 1886 { |
1877 // avoid ubsan error for overflow | 1887 // avoid ubsan error for overflow |
1878 if (un <= UVARNUM_MAX / 8) | 1888 if (un <= UVARNUM_MAX / 8) |
1879 un = 8 * un + (uvarnumber_T)(*ptr - '0'); | 1889 un = 8 * un + (uvarnumber_T)(*ptr - '0'); |