dsp                                      Tue, 24 Nov 2009 13:33:35 +0000

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

Log:
Implement feature request #50283 (allow base in gmp_strval to use full range: 2 
to 62, and -2 to -36)

Bug: http://bugs.php.net/50283 (Open) allow base in gmp_strval to use full 
range: 2 to 62, and -2 to -36
      
Changed paths:
    U   php/php-src/branches/PHP_5_2/NEWS
    U   php/php-src/branches/PHP_5_2/ext/gmp/gmp.c
    A   php/php-src/branches/PHP_5_2/ext/gmp/tests/bug50283.phpt
    U   php/php-src/branches/PHP_5_3/ext/gmp/gmp.c
    A   php/php-src/branches/PHP_5_3/ext/gmp/tests/bug50283.phpt
    U   php/php-src/trunk/ext/gmp/gmp.c
    A   php/php-src/trunk/ext/gmp/tests/bug50283.phpt

Modified: php/php-src/branches/PHP_5_2/NEWS
===================================================================
--- php/php-src/branches/PHP_5_2/NEWS   2009-11-24 12:19:56 UTC (rev 291261)
+++ php/php-src/branches/PHP_5_2/NEWS   2009-11-24 13:33:35 UTC (rev 291262)
@@ -8,6 +8,8 @@

 - Fixed error_log() to be binary safe when using message_type 3. (Jani)

+- Implement feature request #50283 (allow base in gmp_strval to use full
+  range: 2 to 62, and -2 to -36). (David Soria Parra)
 - Fixed bug #50282 (xmlrpc_encode_request() changes object into array in
   calling function). (Felipe)
 - Fixed bug #50219 (soap call Segmentation fault on a redirected url).

Modified: php/php-src/branches/PHP_5_2/ext/gmp/gmp.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/gmp/gmp.c  2009-11-24 12:19:56 UTC (rev 
291261)
+++ php/php-src/branches/PHP_5_2/ext/gmp/gmp.c  2009-11-24 13:33:35 UTC (rev 
291262)
@@ -817,12 +817,12 @@
                        break;
        }

-       if (base < 2 || base > 36) {
+       if ((base < 2 && base > -2) || base > 36 || base < -36) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for 
conversion: %d", base);
                RETURN_FALSE;
        }

-       num_len = mpz_sizeinbase(*gmpnum, base);
+       num_len = mpz_sizeinbase(*gmpnum, abs(base));
        out_string = emalloc(num_len+2);
        if (mpz_sgn(*gmpnum) < 0) {
                num_len++;

Added: php/php-src/branches/PHP_5_2/ext/gmp/tests/bug50283.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/ext/gmp/tests/bug50283.phpt                    
        (rev 0)
+++ php/php-src/branches/PHP_5_2/ext/gmp/tests/bug50283.phpt    2009-11-24 
13:33:35 UTC (rev 291262)
@@ -0,0 +1,29 @@
+--TEST--
+Feature Request #50283 (allow base in gmp_strval to use full range: 2 to 62, 
and -2 to -36)
+--SKIPIF--
+<?php if (!extension_loaded("gmp")) print "skip"; ?>
+--FILE--
+<?php
+$a = gmp_init("0x41682179fbf5");
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,-36));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,36));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,-1));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,1));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,-37));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,37));
+?>
+--EXPECTF--
+Decimal: 71915494046709, 36-based: PHPISCOOL
+Decimal: 71915494046709, 36-based: phpiscool
+
+Warning: gmp_strval(): Bad base for conversion: -1 in %s on line 5
+Decimal: 71915494046709, 36-based:
+
+Warning: gmp_strval(): Bad base for conversion: 1 in %s on line 6
+Decimal: 71915494046709, 36-based:
+
+Warning: gmp_strval(): Bad base for conversion: -37 in %s on line 7
+Decimal: 71915494046709, 36-based:
+
+Warning: gmp_strval(): Bad base for conversion: 37 in %s on line 8
+Decimal: 71915494046709, 36-based:

Modified: php/php-src/branches/PHP_5_3/ext/gmp/gmp.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/gmp/gmp.c  2009-11-24 12:19:56 UTC (rev 
291261)
+++ php/php-src/branches/PHP_5_3/ext/gmp/gmp.c  2009-11-24 13:33:35 UTC (rev 
291262)
@@ -796,14 +796,14 @@
                return;
        }

-       if (base < 2 || base > 36) {
+       if ((base < 2 && base > -2) || base > 36 || base < -36) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for 
conversion: %ld", base);
                RETURN_FALSE;
        }

        FETCH_GMP_ZVAL(gmpnum, gmpnumber_arg, temp_a);

-       num_len = mpz_sizeinbase(*gmpnum, base);
+       num_len = mpz_sizeinbase(*gmpnum, abs(base));
        out_string = emalloc(num_len+2);
        if (mpz_sgn(*gmpnum) < 0) {
                num_len++;

Added: php/php-src/branches/PHP_5_3/ext/gmp/tests/bug50283.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/gmp/tests/bug50283.phpt                    
        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/gmp/tests/bug50283.phpt    2009-11-24 
13:33:35 UTC (rev 291262)
@@ -0,0 +1,29 @@
+--TEST--
+Feature Request #50283 (allow base in gmp_strval to use full range: 2 to 62, 
and -2 to -36)
+--SKIPIF--
+<?php if (!extension_loaded("gmp")) print "skip"; ?>
+--FILE--
+<?php
+$a = gmp_init("0x41682179fbf5");
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,-36));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,36));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,-1));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,1));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,-37));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,37));
+?>
+--EXPECTF--
+Decimal: 71915494046709, 36-based: PHPISCOOL
+Decimal: 71915494046709, 36-based: phpiscool
+
+Warning: gmp_strval(): Bad base for conversion: -1 in %s on line 5
+Decimal: 71915494046709, 36-based:
+
+Warning: gmp_strval(): Bad base for conversion: 1 in %s on line 6
+Decimal: 71915494046709, 36-based:
+
+Warning: gmp_strval(): Bad base for conversion: -37 in %s on line 7
+Decimal: 71915494046709, 36-based:
+
+Warning: gmp_strval(): Bad base for conversion: 37 in %s on line 8
+Decimal: 71915494046709, 36-based:

Modified: php/php-src/trunk/ext/gmp/gmp.c
===================================================================
--- php/php-src/trunk/ext/gmp/gmp.c     2009-11-24 12:19:56 UTC (rev 291261)
+++ php/php-src/trunk/ext/gmp/gmp.c     2009-11-24 13:33:35 UTC (rev 291262)
@@ -804,14 +804,14 @@
                return;
        }

-       if (base < 2 || base > 36) {
+       if ((base < 2 && base > -2) || base > 36 || base < -36) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for 
conversion: %ld", base);
                RETURN_FALSE;
        }

        FETCH_GMP_ZVAL(gmpnum, gmpnumber_arg, temp_a);

-       num_len = mpz_sizeinbase(*gmpnum, base);
+       num_len = mpz_sizeinbase(*gmpnum, abs(base));
        out_string = emalloc(num_len+2);
        if (mpz_sgn(*gmpnum) < 0) {
                num_len++;

Added: php/php-src/trunk/ext/gmp/tests/bug50283.phpt
===================================================================
--- php/php-src/trunk/ext/gmp/tests/bug50283.phpt                               
(rev 0)
+++ php/php-src/trunk/ext/gmp/tests/bug50283.phpt       2009-11-24 13:33:35 UTC 
(rev 291262)
@@ -0,0 +1,29 @@
+--TEST--
+Feature Request #50283 (allow base in gmp_strval to use full range: 2 to 62, 
and -2 to -36)
+--SKIPIF--
+<?php if (!extension_loaded("gmp")) print "skip"; ?>
+--FILE--
+<?php
+$a = gmp_init("0x41682179fbf5");
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,-36));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,36));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,-1));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,1));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,-37));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,37));
+?>
+--EXPECTF--
+Decimal: 71915494046709, 36-based: PHPISCOOL
+Decimal: 71915494046709, 36-based: phpiscool
+
+Warning: gmp_strval(): Bad base for conversion: -1 in %s on line 5
+Decimal: 71915494046709, 36-based:
+
+Warning: gmp_strval(): Bad base for conversion: 1 in %s on line 6
+Decimal: 71915494046709, 36-based:
+
+Warning: gmp_strval(): Bad base for conversion: -37 in %s on line 7
+Decimal: 71915494046709, 36-based:
+
+Warning: gmp_strval(): Bad base for conversion: 37 in %s on line 8
+Decimal: 71915494046709, 36-based:

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

Reply via email to