@@ -120,7 +120,7 @@ do { \
120
120
121
121
BEGIN_EXTERN_C ()
122
122
123
- static void strip_underscores(char *str, int *len)
123
+ static void strip_underscores(char *str, size_t *len)
124
124
{
125
125
char *src = str, *dest = str;
126
126
while (*src != ' \0 ' ) {
@@ -1771,8 +1771,9 @@ NEWLINE ("\r"|"\n"|"\r\n")
1771
1771
1772
1772
<ST_IN_SCRIPTING>{BNUM} {
1773
1773
/* The +/- 2 skips "0b" */
1774
- int len = yyleng - 2 , contains_underscores ;
1774
+ size_t len = yyleng - 2 ;
1775
1775
char *end, *bin = yytext + 2 ;
1776
+ zend_bool contains_underscores;
1776
1777
1777
1778
/* Skip any leading 0s */
1778
1779
while (len > 0 && (*bin == ' 0' || *bin == ' _' )) {
@@ -1811,10 +1812,25 @@ NEWLINE ("\r"|"\n"|"\r\n")
1811
1812
}
1812
1813
1813
1814
<ST_IN_SCRIPTING>{LNUM} {
1814
- int len = yyleng, contains_underscores ;
1815
+ size_t len = yyleng;
1815
1816
char *end, *lnum = yytext;
1816
-
1817
- contains_underscores = (memchr (lnum, ' _' , len) != NULL );
1817
+ zend_bool is_octal = lnum[0 ] == ' 0' ;
1818
+ zend_bool contains_underscores = (memchr (lnum, ' _' , len) != NULL );
1819
+
1820
+ /* Digits 8 and 9 are illegal in octal literals. */
1821
+ if (is_octal) {
1822
+ size_t i;
1823
+ for (i = 0 ; i < len; i++) {
1824
+ if (lnum[i] == ' 8' || lnum[i] == ' 9' ) {
1825
+ zend_throw_exception (zend_ce_parse_error, " Invalid numeric literal" , 0 );
1826
+ ZVAL_UNDEF (zendlval);
1827
+ if (PARSER_MODE ()) {
1828
+ RETURN_TOKEN (T_ERROR);
1829
+ }
1830
+ RETURN_TOKEN_WITH_VAL (T_LNUMBER);
1831
+ }
1832
+ }
1833
+ }
1818
1834
1819
1835
if (contains_underscores) {
1820
1836
lnum = estrndup (lnum, len);
@@ -1824,21 +1840,8 @@ NEWLINE ("\r"|"\n"|"\r\n")
1824
1840
if (len < MAX_LENGTH_OF_LONG - 1 ) { /* Won't overflow */
1825
1841
errno = 0 ;
1826
1842
/* base must be passed explicitly for correct parse error on Windows */
1827
- ZVAL_LONG (zendlval, ZEND_STRTOL (lnum, &end, lnum[0 ] == ' 0' ? 8 : 10 ));
1828
- /* This isn't an assert, we need to ensure 019 isn't valid octal
1829
- * Because the lexing itself doesn't do that for us
1830
- */
1831
- if (end != lnum + len) {
1832
- zend_throw_exception (zend_ce_parse_error, " Invalid numeric literal" , 0 );
1833
- ZVAL_UNDEF (zendlval);
1834
- if (contains_underscores) {
1835
- efree (lnum);
1836
- }
1837
- if (PARSER_MODE ()) {
1838
- RETURN_TOKEN (T_ERROR);
1839
- }
1840
- RETURN_TOKEN_WITH_VAL (T_LNUMBER);
1841
- }
1843
+ ZVAL_LONG (zendlval, ZEND_STRTOL (lnum, &end, is_octal ? 8 : 10 ));
1844
+ ZEND_ASSERT (end == lnum + len);
1842
1845
} else {
1843
1846
errno = 0 ;
1844
1847
ZVAL_LONG (zendlval, ZEND_STRTOL (lnum, &end, 0 ));
@@ -1849,35 +1852,13 @@ NEWLINE ("\r"|"\n"|"\r\n")
1849
1852
} else {
1850
1853
ZVAL_DOUBLE (zendlval, zend_strtod (lnum, (const char **)&end));
1851
1854
}
1852
- /* Also not an assert for the same reason */
1853
- if (end != lnum + len) {
1854
- zend_throw_exception (zend_ce_parse_error,
1855
- " Invalid numeric literal" , 0 );
1856
- ZVAL_UNDEF (zendlval);
1857
- if (contains_underscores) {
1858
- efree (lnum);
1859
- }
1860
- if (PARSER_MODE ()) {
1861
- RETURN_TOKEN (T_ERROR);
1862
- }
1863
- }
1855
+ ZEND_ASSERT (end == lnum + len);
1864
1856
if (contains_underscores) {
1865
1857
efree (lnum);
1866
1858
}
1867
1859
RETURN_TOKEN_WITH_VAL (T_DNUMBER);
1868
1860
}
1869
- /* Also not an assert for the same reason */
1870
- if (end != lnum + len) {
1871
- zend_throw_exception (zend_ce_parse_error, " Invalid numeric literal" , 0 );
1872
- ZVAL_UNDEF (zendlval);
1873
- if (contains_underscores) {
1874
- efree (lnum);
1875
- }
1876
- if (PARSER_MODE ()) {
1877
- RETURN_TOKEN (T_ERROR);
1878
- }
1879
- RETURN_TOKEN_WITH_VAL (T_DNUMBER);
1880
- }
1861
+ ZEND_ASSERT (end == lnum + len);
1881
1862
}
1882
1863
ZEND_ASSERT (!errno);
1883
1864
if (contains_underscores) {
@@ -1888,8 +1869,9 @@ NEWLINE ("\r"|"\n"|"\r\n")
1888
1869
1889
1870
<ST_IN_SCRIPTING>{HNUM} {
1890
1871
/* The +/- 2 skips "0x" */
1891
- int len = yyleng - 2 , contains_underscores ;
1872
+ size_t len = yyleng - 2 ;
1892
1873
char *end, *hex = yytext + 2 ;
1874
+ zend_bool contains_underscores;
1893
1875
1894
1876
/* Skip any leading 0s */
1895
1877
while (len > 0 && (*hex == ' 0' || *hex == ' _' )) {
@@ -1954,10 +1936,9 @@ string:
1954
1936
1955
1937
<ST_IN_SCRIPTING>{DNUM}|{EXPONENT_DNUM} {
1956
1938
const char *end;
1957
- int len = yyleng, contains_underscores ;
1939
+ size_t len = yyleng;
1958
1940
char *dnum = yytext;
1959
-
1960
- contains_underscores = (memchr (dnum, ' _' , len) != NULL );
1941
+ zend_bool contains_underscores = (memchr (dnum, ' _' , len) != NULL );
1961
1942
1962
1943
if (contains_underscores) {
1963
1944
dnum = estrndup (dnum, len);
0 commit comments