php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #50648
Patch php-src-trunk-50648_p2.patch revision 2010-11-29 16:36 UTC by jonah dot harris at gmail dot com
Patch php-src-5.3-50648_p1.patch revision 2010-11-11 06:06 UTC by jonah dot harris at gmail dot com
Patch phpdoc-50648_p1.patch revision 2010-11-11 05:08 UTC by jonah dot harris at gmail dot com

Patch php-src-5.3-50648_p1.patch for Scripting Engine problem Bug #50648

Patch version 2010-11-11 06:06 UTC

Return to Bug #50648 | Download this patch
This patch is obsolete

Obsoleted by patches:

Patch Revisions:

Developer: jonah.harris@gmail.com

diff -ru php-src-5.3/Zend/zend_language_scanner.l php-src-5.3-50648/Zend/zend_language_scanner.l
--- php-src-5.3/Zend/zend_language_scanner.l	2010-11-10 22:22:50.000000000 -0500
+++ php-src-5.3-50648/Zend/zend_language_scanner.l	2010-11-10 23:30:50.000000000 -0500
@@ -849,6 +849,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]*
@@ -1316,6 +1317,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 */
@@ -1371,7 +1392,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 -ru php-src-5.3/Zend/zend_strtod.c php-src-5.3-50648/Zend/zend_strtod.c
--- php-src-5.3/Zend/zend_strtod.c	2010-11-10 22:22:50.000000000 -0500
+++ php-src-5.3-50648/Zend/zend_strtod.c	2010-11-11 00:54:56.000000000 -0500
@@ -2638,6 +2638,44 @@
 	return value;
 }
 
+ZEND_API double zend_bin_strtod(const char *str, 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 -ru php-src-5.3/Zend/zend_strtod.h php-src-5.3-50648/Zend/zend_strtod.h
--- php-src-5.3/Zend/zend_strtod.h	2010-11-10 22:22:50.000000000 -0500
+++ php-src-5.3-50648/Zend/zend_strtod.h	2010-11-11 00:04:48.000000000 -0500
@@ -30,6 +30,7 @@
 ZEND_API double zend_strtod(const char *s00, char **se);
 ZEND_API double zend_hex_strtod(const char *str, char **endptr);
 ZEND_API double zend_oct_strtod(const char *str, char **endptr);
+ZEND_API double zend_bin_strtod(const char *str, char **endptr);
 ZEND_API int zend_startup_strtod(void);
 ZEND_API int zend_shutdown_strtod(void);
 END_EXTERN_C()

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC