]> granicus.if.org Git - php/commitdiff
Additional fix for bug #42868
authorDmitry Stogov <dmitry@php.net>
Mon, 24 Dec 2007 18:09:50 +0000 (18:09 +0000)
committerDmitry Stogov <dmitry@php.net>
Mon, 24 Dec 2007 18:09:50 +0000 (18:09 +0000)
Zend/tests/int_overflow_64bit.phpt
Zend/zend_operators.c
ext/standard/string.c
ext/standard/tests/strings/chunk_split_error.phpt
ext/standard/tests/strings/chunk_split_variation5.phpt
ext/standard/tests/strings/chunk_split_variation8.phpt
ext/standard/tests/strings/htmlspecialchars_decode_variation2.phpt

index 306fbae602ee86b184ca36f68381405f411dc4f0..769b17926e92490bf2fa7ced1490f79fffcf13ea 100644 (file)
@@ -6,11 +6,13 @@ testing integer overflow (64bit)
 <?php
 
 $doubles = array(
-        9223372036854775808,
-        9223372036854775809,
-        9223372036854775818,
-        9223372036854775908,
-        9223372036854776808,
+        PHP_INT_MAX,
+        PHP_INT_MAX + 1,
+        PHP_INT_MAX + 1000,
+        PHP_INT_MAX * 2 + 4,
+        -PHP_INT_MAX -1,
+        -PHP_INT_MAX -2,
+        -PHP_INT_MAX -1000,
         );
 
 foreach ($doubles as $d) {
@@ -21,8 +23,10 @@ foreach ($doubles as $d) {
 echo "Done\n";
 ?>
 --EXPECTF--
-int(-9223372036854775808)
-int(-9223372036854775808)
+int(9223372036854775807)
+int(9223372036854775807)
+int(9223372036854775807)
+int(9223372036854775807)
 int(-9223372036854775808)
 int(-9223372036854775808)
 int(-9223372036854775808)
index c177c3ec8f6e6219e2fa48b1c0c74c52254e5e4b..c2271f1734412f91e81a8923af209d0df1f098ad 100644 (file)
@@ -186,36 +186,38 @@ ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC)
 #define MAX_UNSIGNED_INT ((double) LONG_MAX * 2) + 1
 #ifdef _WIN64
 # define DVAL_TO_LVAL(d, l) \
-        if ((d) > LONG_MAX) { \
-                if ((d) > MAX_UNSIGNED_INT) { \
-                        (l) = LONG_MAX; \
-                } else { \
-                        (l) = (long)(unsigned long)(__int64) (d); \
-                } \
-        } else { \
-                if((d) < LONG_MIN) { \
-                        (l) = LONG_MIN; \
-                } else { \
-                        (l) = (long) (d); \
-                } \
-        }
+       if ((d) > LONG_MAX) { \
+               (l) = (long)(unsigned long)(__int64) (d); \
+       } else { \
+               (l) = (long) (d); \
+       }
+#elif !defined(_WIN64) && __WORDSIZE == 64
+# define DVAL_TO_LVAL(d, l) \
+       if ((d) >= LONG_MAX) { \
+               (l) = LONG_MAX; \
+       } else if ((d) <=  LONG_MIN) { \
+               (l) = LONG_MIN; \
+       } else {\
+               (l) = (long) (d); \
+       } 
 #else
 # define DVAL_TO_LVAL(d, l) \
-        if ((d) > LONG_MAX) { \
-                if ((d) > MAX_UNSIGNED_INT) { \
-                        (l) = LONG_MAX; \
-                } else { \
-                        (l) = (unsigned long) (d); \
-                } \
-        } else { \
-                if((d) < LONG_MIN) { \
-                        (l) = LONG_MIN; \
-                } else { \
-                        (l) = (long) (d); \
-                } \
-        }
+       if ((d) > LONG_MAX) { \
+               if ((d) > MAX_UNSIGNED_INT) { \
+                       (l) = LONG_MAX; \
+               } else { \
+                       (l) = (unsigned long) (d); \
+               } \
+       } else { \
+               if((d) < LONG_MIN) { \
+                       (l) = LONG_MIN; \
+               } else { \
+                       (l) = (long) (d); \
+               } \
+       } 
 #endif
 
+
 #define zendi_convert_to_long(op, holder, result)                                      \
        if (op == result) {                                                                                             \
                convert_to_long(op);                                                                            \
index fd6ed395e228f0cc5e41b726f32ec4fa6f4866cc..6e9727e1dae368aab7f7978336bfa80fcfb6173f 100644 (file)
@@ -2182,12 +2182,12 @@ PHP_FUNCTION(chunk_split)
        char *result;
        char *end    = "\r\n";
        int endlen   = 2;
-       int chunklen = 76;
+       long chunklen = 76;
        int result_len;
        int argc = ZEND_NUM_ARGS();
 
-       if (argc < 1 || argc > 3 ||     zend_get_parameters_ex(argc, &p_str, &p_chunklen, &p_ending) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z|ZZ", &p_str, &p_chunklen, &p_ending) == FAILURE) {
+               return;
        }
 
        convert_to_string_ex(p_str);
index 153250c1ae5412fd16065467256fdedc872dc575..9313b65b5b8caf842b542b26999e352a79aec42f 100644 (file)
@@ -32,9 +32,9 @@ echo "Done"
 --EXPECTF--
 *** Testing chunk_split() : error conditions ***
 -- Testing chunk_split() function with Zero arguments --
-Warning: Wrong parameter count for chunk_split() in %s on line %d
+Warning: chunk_split() expects at least 1 parameter, 0 given in %s on line %d
 NULL
 -- Testing chunk_split() function with more than expected no. of arguments --
-Warning: Wrong parameter count for chunk_split() in %s on line %d
+Warning: chunk_split() expects at most 3 parameters, 4 given in %s on line %d
 NULL
 Done
index 69308ea309b284379695ec99b05c83b39902ed8b..e01c126d3d18cebd7f67f92a5eac4628cfbf3635 100644 (file)
Binary files a/ext/standard/tests/strings/chunk_split_variation5.phpt and b/ext/standard/tests/strings/chunk_split_variation5.phpt differ
index cc6eeef98c03df4ac7dd744d4c7112b919d90dde..6f8f2cde7f0cd938b15abf018c9d0014b0c50c9c 100644 (file)
@@ -32,9 +32,9 @@ $values = array (
   -123,  //negative integer
   0234,  //octal number
   0x1A,  //hexadecimal number
-  2147483647,  //max positive integer number
-  2147483648,  //max positive integer+1
-  -2147483648,  //min negative integer
+  PHP_INT_MAX,  //max positive integer number
+  PHP_INT_MAX * 3,  // Will overflow 32 bits on 32 bt system and 64 bits on 64 bit system
+  -PHP_INT_MAX -1,  //min negative integer
 
 );
 
@@ -78,9 +78,10 @@ string(129) "This's heredoc string with       and
 It has _speci@l ch@r$ 2222 !!!Now \k as escape char to test
 chunk_split():::"
 -- Iteration 7 --
-
-Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
-bool(false)
+string(129) "This's heredoc string with         and 
+ white space char.
+It has _speci@l ch@r$ 2222 !!!Now \k as escape char to test
+chunk_split():::"
 -- Iteration 8 --
 
 Warning: chunk_split(): Chunk length should be greater than zero in %s on line %d
index 9ac06218960170b3da7b3906760201a4f8f43246..ece2ac7b90650811699791d647a681dfcda22fff 100644 (file)
@@ -37,7 +37,7 @@ $values = array(
       // float data
       10.5,
       -10.5,
-      10.5e10,
+      10.5e20,
       10.6E-10,
       .5,