mike                                     Wed, 19 May 2010 11:28:08 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=299484

Log:
* fixed bug #47842      sscanf() does not support 64-bit values

Bug: http://bugs.php.net/47842 (Open) sscanf() does not support 64-bit values
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/standard/scanf.c
    A   php/php-src/branches/PHP_5_3/ext/standard/tests/strings/bug47842.phpt
    U   php/php-src/trunk/ext/standard/scanf.c
    A   php/php-src/trunk/ext/standard/tests/strings/bug47842.phpt

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2010-05-19 10:08:20 UTC (rev 299483)
+++ php/php-src/branches/PHP_5_3/NEWS   2010-05-19 11:28:08 UTC (rev 299484)
@@ -171,6 +171,7 @@
   parent dir). (Etienne)
 - Fixed bug #48289 (iconv_mime_encode() quoted-printable scheme is broken).
   (Adam, patch from hiroaki dot kawai at gmail dot com).
+- Fixed bug #47842 (sscanf() does not support 64-bit values). (Mike)
 - Fixed bug #46111 (Some timezone identifiers can not be parsed). (Derick)
 - Fixed bug #43233 (sasl support for ldap on Windows). (Pierre)
 - Fixed bug #35673 (formatOutput does not work with saveHTML). (Rob)

Modified: php/php-src/branches/PHP_5_3/ext/standard/scanf.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/scanf.c   2010-05-19 10:08:20 UTC 
(rev 299483)
+++ php/php-src/branches/PHP_5_3/ext/standard/scanf.c   2010-05-19 11:28:08 UTC 
(rev 299484)
@@ -581,7 +581,8 @@
                                int varStart, zval **return_value TSRMLS_DC)
 {
        int  numVars, nconversions, totalVars = -1;
-       int  i, value, result;
+       int  i, result;
+       long value;
        int  objIndex;
        char *end, *baseString;
        zval **current;
@@ -1059,9 +1060,9 @@
                                 */
                                if (!(flags & SCAN_SUPPRESS)) {
                                        *end = '\0';
-                                       value = (int) (*fn)(buf, NULL, base);
+                                       value = (long) (*fn)(buf, NULL, base);
                                        if ((flags & SCAN_UNSIGNED) && (value < 
0)) {
-                                               snprintf(buf, sizeof(buf), 
"%u", value); /* INTL: ISO digit */
+                                               snprintf(buf, sizeof(buf), 
"%lu", value); /* INTL: ISO digit */
                                                if (numVars && objIndex >= 
argCount) {
                                                        break;
                                                } else if (numVars) {

Added: php/php-src/branches/PHP_5_3/ext/standard/tests/strings/bug47842.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/tests/strings/bug47842.phpt       
                        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/standard/tests/strings/bug47842.phpt       
2010-05-19 11:28:08 UTC (rev 299484)
@@ -0,0 +1,34 @@
+--TEST--
+Bug #47842      sscanf() does not support 64-bit values
+--SKIPIF--
+<?php
+if (PHP_INT_MAX < pow(2,31)) die("skip PHP_INT_MAX < 32b\n");
+?>
+--FILE--
+<?php
+echo "-Test\n";
+
+sscanf("2147483647", '%d', $int);
+echo "sscanf 32-bit signed int '2147483647'           (2^31)-1 = ",$int,"\n";
+sscanf("4294967295", '%u', $int);
+echo "sscanf 32-bit unsign int '4294967295'           (2^32)-1 = ",$int,"\n";
+
+sscanf("9223372036854775807", '%d', $int);
+echo "sscanf 64-bit signed int '9223372036854775807'  (2^63)-1 = ",$int,"\n";
+sscanf("18446744073709551615", '%u', $int);
+echo "sscanf 64-bit unsign int '18446744073709551615' (2^64)-1 = ",$int,"\n";
+
+printf("printf 64-bit signed int '9223372036854775807'  (2^63)-1 = %d\n", 
9223372036854775807);
+printf("printf 64-bit signed int '18446744073709551615' (2^64)-1 = %u\n", 
18446744073709551615);
+
+echo "Done\n";
+?>
+--EXPECTF--
+%aTest
+sscanf 32-bit signed int '2147483647'           (2^31)-1 = 2147483647
+sscanf 32-bit unsign int '4294967295'           (2^32)-1 = 4294967295
+sscanf 64-bit signed int '9223372036854775807'  (2^63)-1 = 9223372036854775807
+sscanf 64-bit unsign int '18446744073709551615' (2^64)-1 = 18446744073709551615
+printf 64-bit signed int '9223372036854775807'  (2^63)-1 = 9223372036854775807
+printf 64-bit signed int '18446744073709551615' (2^64)-1 = 0
+Done

Modified: php/php-src/trunk/ext/standard/scanf.c
===================================================================
--- php/php-src/trunk/ext/standard/scanf.c      2010-05-19 10:08:20 UTC (rev 
299483)
+++ php/php-src/trunk/ext/standard/scanf.c      2010-05-19 11:28:08 UTC (rev 
299484)
@@ -581,7 +581,8 @@
                                int varStart, zval **return_value TSRMLS_DC)
 {
        int  numVars, nconversions, totalVars = -1;
-       int  i, value, result;
+       int  i, result;
+       long value;
        int  objIndex;
        char *end, *baseString;
        zval **current;
@@ -1059,9 +1060,9 @@
                                 */
                                if (!(flags & SCAN_SUPPRESS)) {
                                        *end = '\0';
-                                       value = (int) (*fn)(buf, NULL, base);
+                                       value = (long) (*fn)(buf, NULL, base);
                                        if ((flags & SCAN_UNSIGNED) && (value < 
0)) {
-                                               snprintf(buf, sizeof(buf), 
"%u", value); /* INTL: ISO digit */
+                                               snprintf(buf, sizeof(buf), 
"%lu", value); /* INTL: ISO digit */
                                                if (numVars && objIndex >= 
argCount) {
                                                        break;
                                                } else if (numVars) {

Added: php/php-src/trunk/ext/standard/tests/strings/bug47842.phpt
===================================================================
--- php/php-src/trunk/ext/standard/tests/strings/bug47842.phpt                  
        (rev 0)
+++ php/php-src/trunk/ext/standard/tests/strings/bug47842.phpt  2010-05-19 
11:28:08 UTC (rev 299484)
@@ -0,0 +1,34 @@
+--TEST--
+Bug #47842      sscanf() does not support 64-bit values
+--SKIPIF--
+<?php
+if (PHP_INT_MAX < pow(2,31)) die("skip PHP_INT_MAX < 32b\n");
+?>
+--FILE--
+<?php
+echo "-Test\n";
+
+sscanf("2147483647", '%d', $int);
+echo "sscanf 32-bit signed int '2147483647'           (2^31)-1 = ",$int,"\n";
+sscanf("4294967295", '%u', $int);
+echo "sscanf 32-bit unsign int '4294967295'           (2^32)-1 = ",$int,"\n";
+
+sscanf("9223372036854775807", '%d', $int);
+echo "sscanf 64-bit signed int '9223372036854775807'  (2^63)-1 = ",$int,"\n";
+sscanf("18446744073709551615", '%u', $int);
+echo "sscanf 64-bit unsign int '18446744073709551615' (2^64)-1 = ",$int,"\n";
+
+printf("printf 64-bit signed int '9223372036854775807'  (2^63)-1 = %d\n", 
9223372036854775807);
+printf("printf 64-bit signed int '18446744073709551615' (2^64)-1 = %u\n", 
18446744073709551615);
+
+echo "Done\n";
+?>
+--EXPECTF--
+%aTest
+sscanf 32-bit signed int '2147483647'           (2^31)-1 = 2147483647
+sscanf 32-bit unsign int '4294967295'           (2^32)-1 = 4294967295
+sscanf 64-bit signed int '9223372036854775807'  (2^63)-1 = 9223372036854775807
+sscanf 64-bit unsign int '18446744073709551615' (2^64)-1 = 18446744073709551615
+printf 64-bit signed int '9223372036854775807'  (2^63)-1 = 9223372036854775807
+printf 64-bit signed int '18446744073709551615' (2^64)-1 = 0
+Done

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to