Hi Ilia, all,
I've attached patches for what I think is a better fix here, and it
simplifies the code. Looking at the CVS log, the is_numeric_string() usage
was added in version 1.120 to fix the first numeric key bug. The simple,
better thing would've been to just change zend_hash... to zend_symtable...,
as I've done now. Ilia, this is basically the same fix as Bug #38464 for
array_count_values().
Again, the "symtable" function will handle numeric string keys as elsewhere
in PHP. The only thing that changes from the current code is that strings
with leading whitespace, + sign, or 0s won't be considered numeric again
(e.g. back to behavior before the "symtable" functions were created), which
should be correct if you don't want more future bug reports. ;-)
Matt
----- Original Message -----
From: "Ilia Alshanetsky"
Sent: Saturday, May 05, 2007
> iliaa Sat May 5 15:14:56 2007 UTC
>
> Added files: (Branch: PHP_5_2)
> /php-src/ext/wddx/tests bug41283.phpt
>
> Modified files:
> /php-src NEWS
> /php-src/ext/wddx wddx.c
> Log:
>
> Fixed bug #41283 (Bug with serializing array key that are doubles or
> floats).
>
>
http://cvs.php.net/viewvc.cgi/php-src/ext/wddx/wddx.c?r1=1.119.2.10.2.15&r2=1.119.2.10.2.16&diff_format=u
> Index: php-src/ext/wddx/wddx.c
> diff -u php-src/ext/wddx/wddx.c:1.119.2.10.2.15
php-src/ext/wddx/wddx.c:1.119.2.10.2.16
> --- php-src/ext/wddx/wddx.c:1.119.2.10.2.15 Sun Mar 4 04:38:43 2007
> +++ php-src/ext/wddx/wddx.c Sat May 5 15:14:56 2007
> @@ -16,7 +16,7 @@
>
+----------------------------------------------------------------------+
> */
>
> -/* $Id: wddx.c,v 1.119.2.10.2.15 2007/03/04 04:38:43 stas Exp $ */
> +/* $Id: wddx.c,v 1.119.2.10.2.16 2007/05/05 15:14:56 iliaa Exp $ */
>
> #ifdef HAVE_CONFIG_H
> #include "config.h"
> @@ -984,6 +984,9 @@
> goto bigint;
> }
> l = (long) d;
> + if (l != d) {
> + goto bigint;
> + }
> case IS_LONG:
> zend_hash_index_update(target_hash, l, &ent1->data, sizeof(zval *),
NULL);
> break;
>
Index: ext/wddx/wddx.c
===================================================================
RCS file: /repository/php-src/ext/wddx/wddx.c,v
retrieving revision 1.144
diff -u -r1.144 wddx.c
--- ext/wddx/wddx.c 24 Feb 2007 16:25:55 -0000 1.144
+++ ext/wddx/wddx.c 8 May 2007 09:07:59 -0000
@@ -975,22 +975,7 @@
add_property_zval(ent2->data,
ent1->varname, ent1->data);
EG(scope) = old_scope;
} else {
- long l;
- double d;
-
- switch
(is_numeric_string(ent1->varname, strlen(ent1->varname), &l, &d, 0)) {
- case IS_DOUBLE:
- if (d >
INT_MAX) {
- goto
bigint;
- }
- l = (long) d;
- case IS_LONG:
-
zend_hash_index_update(target_hash, l, &ent1->data, sizeof(zval *), NULL);
- break;
- default:
-bigint:
-
zend_hash_update(target_hash,ent1->varname, strlen(ent1->varname)+1,
&ent1->data, sizeof(zval *), NULL);
- }
+
zend_symtable_update(target_hash, ent1->varname, strlen(ent1->varname)+1,
&ent1->data, sizeof(zval *), NULL);
}
efree(ent1->varname);
} else {
Index: ext/wddx/wddx.c
===================================================================
RCS file: /repository/php-src/ext/wddx/wddx.c,v
retrieving revision 1.119.2.10.2.16
diff -u -r1.119.2.10.2.16 wddx.c
--- ext/wddx/wddx.c 5 May 2007 15:14:56 -0000 1.119.2.10.2.16
+++ ext/wddx/wddx.c 8 May 2007 09:08:34 -0000
@@ -974,26 +974,7 @@
add_property_zval(ent2->data,
ent1->varname, ent1->data);
EG(scope) = old_scope;
} else {
- long l;
- double d;
- int varname_len =
strlen(ent1->varname);
-
- switch
(is_numeric_string(ent1->varname, varname_len, &l, &d, 0)) {
- case IS_DOUBLE:
- if (d >
INT_MAX) {
- goto
bigint;
- }
- l = (long) d;
- if (l != d) {
- goto
bigint;
- }
- case IS_LONG:
-
zend_hash_index_update(target_hash, l, &ent1->data, sizeof(zval *), NULL);
- break;
- default:
-bigint:
-
zend_hash_update(target_hash,ent1->varname, varname_len + 1, &ent1->data,
sizeof(zval *), NULL);
- }
+
zend_symtable_update(target_hash, ent1->varname, strlen(ent1->varname)+1,
&ent1->data, sizeof(zval *), NULL);
}
efree(ent1->varname);
} else {
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php