summaryrefslogtreecommitdiff
path: root/Zend/zend_API.c
diff options
context:
space:
mode:
authorMatt Wilmas <mattwil@php.net>2009-06-04 18:20:45 +0000
committerMatt Wilmas <mattwil@php.net>2009-06-04 18:20:45 +0000
commitb907aa43311ab0b5430d2713a54414baaf9c7e20 (patch)
tree397f1697ff3ff689eea6ff04611831939df02ef0 /Zend/zend_API.c
parent1787a2272a7d9f3f7c7932f61b57054755e99135 (diff)
downloadphp-git-b907aa43311ab0b5430d2713a54414baaf9c7e20.tar.gz
MFH:
Restored double->long conversion behavior to that of PHP 5.2 (on most platforms) and prior: * Out-of-range numbers overflow/preserve least significant bits (no LONG_MAX/MIN limit) * See bug #42868 (presumably-rare platform with different results in 5.2) * On 32-bit platforms with 64-bit long type, a zend_long64 cast has been added, otherwise it's the same as 5.2 * Use this conversion method everywhere instead of some plain (long) casts Added 'L' parameter parsing specifier to ensure a LONG_MAX/MIN limit: * Essentially what 5.3's new conversion was doing in most cases * Functions with "limit" or "length" type params could be updated to use this, and prevent confusing overflow behavior with huge numbers (*also* in 5.2) - See bug #47854, for example; or even #42868 again # Test updates coming
Diffstat (limited to 'Zend/zend_API.c')
-rw-r--r--Zend/zend_API.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index 0e186691d7..d4c1036a74 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -313,6 +313,7 @@ static char *zend_parse_arg_impl(int arg_num, zval **arg, va_list *va, char **sp
switch (c) {
case 'l':
+ case 'L':
{
long *p = va_arg(*va, long *);
switch (Z_TYPE_PP(arg)) {
@@ -324,14 +325,33 @@ static char *zend_parse_arg_impl(int arg_num, zval **arg, va_list *va, char **sp
if ((type = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), p, &d, -1)) == 0) {
return "long";
} else if (type == IS_DOUBLE) {
- *p = (long) d;
+ if (c == 'L') {
+ if (d > LONG_MAX) {
+ *p = LONG_MAX;
+ break;
+ } else if (d < LONG_MIN) {
+ *p = LONG_MIN;
+ break;
+ }
+ }
+
+ *p = zend_dval_to_lval(d);
}
}
break;
+ case IS_DOUBLE:
+ if (c == 'L') {
+ if (Z_DVAL_PP(arg) > LONG_MAX) {
+ *p = LONG_MAX;
+ break;
+ } else if (Z_DVAL_PP(arg) < LONG_MIN) {
+ *p = LONG_MIN;
+ break;
+ }
+ }
case IS_NULL:
case IS_LONG:
- case IS_DOUBLE:
case IS_BOOL:
convert_to_long_ex(arg);
*p = Z_LVAL_PP(arg);