![]() |
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patch php-src-trunk-50648_p2.patch for Scripting Engine problem Bug #50648Patch version 2010-11-29 16:36 UTC Return to Bug #50648 | Download this patchThis patch renders other patches obsolete Obsolete patches: Patch Revisions:Developer: jonah.harris@gmail.comdiff -ur php-src-trunk/Zend/zend_language_scanner.l php-src-trunk-50648/Zend/zend_language_scanner.l --- php-src-trunk/Zend/zend_language_scanner.l 2010-11-29 09:26:23.550799024 -0500 +++ php-src-trunk-50648/Zend/zend_language_scanner.l 2010-11-29 09:30:26.860799084 -0500 @@ -842,6 +842,7 @@ DNUM ([0-9]*"."[0-9]+)|([0-9]+"."[0-9]*) EXPONENT_DNUM (({LNUM}|{DNUM})[eE][+-]?{LNUM}) HNUM "0x"[0-9a-fA-F]+ +BNUM "0b"[01]+ LABEL [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* WHITESPACE [ \n\r\t]+ TABS_AND_SPACES [ \t]* @@ -1373,6 +1374,26 @@ goto restart; } +<ST_IN_SCRIPTING>{BNUM} { + char *bin = yytext + 2; /* Skip "0b" */ + int len = yyleng - 2; + + /* Skip any leading 0s */ + while (*bin == '0') { + ++bin; + --len; + } + + if (len < SIZEOF_LONG * 2) { + zendlval->value.lval = strtol(bin, NULL, 2); + zendlval->type = IS_LONG; + return T_LNUMBER; + } else { + zendlval->value.dval = zend_bin_strtod(bin, NULL); + zendlval->type = IS_DOUBLE; + return T_DNUMBER; + } +} <ST_IN_SCRIPTING>{LNUM} { if (yyleng < MAX_LENGTH_OF_LONG - 1) { /* Won't overflow */ @@ -1428,7 +1449,7 @@ return T_NUM_STRING; } -<ST_VAR_OFFSET>{LNUM}|{HNUM} { /* Offset must be treated as a string */ +<ST_VAR_OFFSET>{LNUM}|{HNUM}|{BNUM} { /* Offset must be treated as a string */ zendlval->value.str.val = (char *)estrndup(yytext, yyleng); zendlval->value.str.len = yyleng; zendlval->type = IS_STRING; diff -ur php-src-trunk/Zend/zend_strtod.c php-src-trunk-50648/Zend/zend_strtod.c --- php-src-trunk/Zend/zend_strtod.c 2010-11-29 09:26:23.580799376 -0500 +++ php-src-trunk-50648/Zend/zend_strtod.c 2010-11-29 09:31:24.710174149 -0500 @@ -2638,6 +2638,44 @@ return value; } +ZEND_API double zend_bin_strtod(const char *str, const char **endptr) +{ + const char *s = str; + char c; + double value = 0; + int any = 0; + + if ('0' == *s && ('b' == s[1] || 'B' == s[1])) { + s += 2; + } + + while ((c = *s++)) { + /* + * Verify the validity of the current character as a base-2 digit. In + * the event that an invalid digit is found, halt the conversion and + * return the portion which has been converted thus far. + */ + if ('0' == c || '1' == c) + value = value * 2 + c - '0'; + else + break; + + any = 1; + } + + /* + * As with many strtoX implementations, should the subject sequence be + * empty or not well-formed, no conversion is performed and the original + * value of str is stored in *endptr, provided that endptr is not a null + * pointer. + */ + if (NULL != endptr) { + *endptr = (char *)(any ? s - 1 : str); + } + + return value; +} + /* * Local variables: * tab-width: 4 diff -ur php-src-trunk/Zend/zend_strtod.h php-src-trunk-50648/Zend/zend_strtod.h --- php-src-trunk/Zend/zend_strtod.h 2010-11-29 09:26:23.590799072 -0500 +++ php-src-trunk-50648/Zend/zend_strtod.h 2010-11-29 09:31:05.170798899 -0500 @@ -30,6 +30,7 @@ ZEND_API double zend_strtod(const char *s00, const char **se); ZEND_API double zend_hex_strtod(const char *str, const char **endptr); ZEND_API double zend_oct_strtod(const char *str, const char **endptr); +ZEND_API double zend_bin_strtod(const char *str, const char **endptr); ZEND_API int zend_startup_strtod(void); ZEND_API int zend_shutdown_strtod(void); END_EXTERN_C() |
![]() All rights reserved. |
Last updated: Wed Mar 12 23:01:31 2025 UTC |