comparison src/charset.c @ 18082:1c7a91cf2356 v8.1.2036

patch 8.1.2036: the str2nr() tests fail Commit: https://github.com/vim/vim/commit/1ac90b4fa63414d56750559506a3e076df6923b0 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 15 14:49:52 2019 +0200 patch 8.1.2036: the str2nr() tests fail Problem: The str2nr() tests fail. Solution: Add missing part of patch.
author Bram Moolenaar <Bram@vim.org>
date Sun, 15 Sep 2019 15:00:03 +0200
parents 59f8948b7590
children 8b0114ffde2b
comparison
equal deleted inserted replaced
18081:25bf4300631b 18082:1c7a91cf2356
1771 * If "unptr" is not NULL, the unsigned result is returned in it. 1771 * If "unptr" is not NULL, the unsigned result is returned in it.
1772 * If "what" contains STR2NR_BIN recognize binary numbers 1772 * If "what" contains STR2NR_BIN recognize binary numbers
1773 * If "what" contains STR2NR_OCT recognize octal numbers 1773 * If "what" contains STR2NR_OCT recognize octal numbers
1774 * If "what" contains STR2NR_HEX recognize hex numbers 1774 * If "what" contains STR2NR_HEX recognize hex numbers
1775 * If "what" contains STR2NR_FORCE always assume bin/oct/hex. 1775 * If "what" contains STR2NR_FORCE always assume bin/oct/hex.
1776 * If "what" contains STR2NR_QUOTE ignore embedded single quotes
1776 * If maxlen > 0, check at a maximum maxlen chars. 1777 * If maxlen > 0, check at a maximum maxlen chars.
1777 * If strict is TRUE, check the number strictly. return *len = 0 if fail. 1778 * If strict is TRUE, check the number strictly. return *len = 0 if fail.
1778 */ 1779 */
1779 void 1780 void
1780 vim_str2nr( 1781 vim_str2nr(
1839 } 1840 }
1840 } 1841 }
1841 1842
1842 // Do the conversion manually to avoid sscanf() quirks. 1843 // Do the conversion manually to avoid sscanf() quirks.
1843 n = 1; 1844 n = 1;
1844 if (pre == 'B' || pre == 'b' || what == STR2NR_BIN + STR2NR_FORCE) 1845 if (pre == 'B' || pre == 'b'
1846 || ((what & STR2NR_BIN) && (what & STR2NR_FORCE)))
1845 { 1847 {
1846 /* bin */ 1848 /* bin */
1847 if (pre != 0) 1849 if (pre != 0)
1848 n += 2; /* skip over "0b" */ 1850 n += 2; /* skip over "0b" */
1849 while ('0' <= *ptr && *ptr <= '1') 1851 while ('0' <= *ptr && *ptr <= '1')
1854 else 1856 else
1855 un = UVARNUM_MAX; 1857 un = UVARNUM_MAX;
1856 ++ptr; 1858 ++ptr;
1857 if (n++ == maxlen) 1859 if (n++ == maxlen)
1858 break; 1860 break;
1859 } 1861 if ((what & STR2NR_QUOTE) && *ptr == '\''
1860 } 1862 && '0' <= ptr[1] && ptr[1] <= '1')
1861 else if (pre == '0' || what == STR2NR_OCT + STR2NR_FORCE) 1863 {
1864 ++ptr;
1865 if (n++ == maxlen)
1866 break;
1867 }
1868 }
1869 }
1870 else if (pre == '0' || ((what & STR2NR_OCT) && (what & STR2NR_FORCE)))
1862 { 1871 {
1863 /* octal */ 1872 /* octal */
1864 while ('0' <= *ptr && *ptr <= '7') 1873 while ('0' <= *ptr && *ptr <= '7')
1865 { 1874 {
1866 /* avoid ubsan error for overflow */ 1875 /* avoid ubsan error for overflow */
1869 else 1878 else
1870 un = UVARNUM_MAX; 1879 un = UVARNUM_MAX;
1871 ++ptr; 1880 ++ptr;
1872 if (n++ == maxlen) 1881 if (n++ == maxlen)
1873 break; 1882 break;
1874 } 1883 if ((what & STR2NR_QUOTE) && *ptr == '\''
1875 } 1884 && '0' <= ptr[1] && ptr[1] <= '7')
1876 else if (pre != 0 || what == STR2NR_HEX + STR2NR_FORCE) 1885 {
1886 ++ptr;
1887 if (n++ == maxlen)
1888 break;
1889 }
1890 }
1891 }
1892 else if (pre != 0 || ((what & STR2NR_HEX) && (what & STR2NR_FORCE)))
1877 { 1893 {
1878 /* hex */ 1894 /* hex */
1879 if (pre != 0) 1895 if (pre != 0)
1880 n += 2; /* skip over "0x" */ 1896 n += 2; /* skip over "0x" */
1881 while (vim_isxdigit(*ptr)) 1897 while (vim_isxdigit(*ptr))
1886 else 1902 else
1887 un = UVARNUM_MAX; 1903 un = UVARNUM_MAX;
1888 ++ptr; 1904 ++ptr;
1889 if (n++ == maxlen) 1905 if (n++ == maxlen)
1890 break; 1906 break;
1907 if ((what & STR2NR_QUOTE) && *ptr == '\'' && vim_isxdigit(ptr[1]))
1908 {
1909 ++ptr;
1910 if (n++ == maxlen)
1911 break;
1912 }
1891 } 1913 }
1892 } 1914 }
1893 else 1915 else
1894 { 1916 {
1895 /* decimal */ 1917 /* decimal */
1904 else 1926 else
1905 un = UVARNUM_MAX; 1927 un = UVARNUM_MAX;
1906 ++ptr; 1928 ++ptr;
1907 if (n++ == maxlen) 1929 if (n++ == maxlen)
1908 break; 1930 break;
1909 } 1931 if ((what & STR2NR_QUOTE) && *ptr == '\'' && VIM_ISDIGIT(ptr[1]))
1910 } 1932 {
1933 ++ptr;
1934 if (n++ == maxlen)
1935 break;
1936 }
1937 }
1938 }
1939
1911 // Check for an alpha-numeric character immediately following, that is 1940 // Check for an alpha-numeric character immediately following, that is
1912 // most likely a typo. 1941 // most likely a typo.
1913 if (strict && n - 1 != maxlen && ASCII_ISALNUM(*ptr)) 1942 if (strict && n - 1 != maxlen && ASCII_ISALNUM(*ptr))
1914 return; 1943 return;
1915 1944