com php-src: Fixed bug #50175: NEWS ext/gmp/gmp.c ext/gmp/tests/bug50175.phpt

From: Date: Tue, 02 Sep 2014 17:04:55 +0000
Subject: com php-src: Fixed bug #50175: NEWS ext/gmp/gmp.c ext/gmp/tests/bug50175.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-81375@lists.php.net to get a copy of this message
Commit: 834daa455bc9c8cde178c6978dcb548119b038e8 Author: Nikita Popov <nikic@php.net> Tue, 2 Sep 2014 19:04:55 +0200 Parents: 7533243f0c78354b299bee5ee06702c66dd3a7cb Branches: PHP-5.6 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=834daa455bc9c8cde178c6978dcb548119b038e8 Log: Fixed bug #50175 0x and 0b prefix is now only handled if either no base is given or if the base is 16 (0x) or 2 (0b). Always handling it is incorrect because 0x and 0b are perfectly valid numbers in other bases. Bugs: https://bugs.php.net/50175 Changed paths: M NEWS M ext/gmp/gmp.c A ext/gmp/tests/bug50175.phpt Diff: diff --git a/NEWS b/NEWS index 1034a5d..f78969c 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,8 @@ PHP NEWS - GMP: . Fixed bug #67917 (Using GMP objects with overloaded operators can cause memory exhaustion). (Nikita) + . Fixed bug #50175 (gmp_init() results 0 on given base and number starting + with 0x or 0b). (Nikita) . Implemented gmp_import() and gmp_export(). (Leigh, Nikita) - MySQLi: diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index bf0f4f3..619f1c3 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -773,15 +773,13 @@ static int convert_to_gmp(mpz_t gmpnumber, zval *val, int base TSRMLS_DC) int skip_lead = 0; int ret; - if (Z_STRLEN_P(val) > 2) { - if (numstr[0] == '0') { - if (numstr[1] == 'x' || numstr[1] == 'X') { - base = 16; - skip_lead = 1; - } else if (base != 16 && (numstr[1] == 'b' || numstr[1] == 'B')) { - base = 2; - skip_lead = 1; - } + if (Z_STRLEN_P(val) > 2 && numstr[0] == '0') { + if ((base == 0 || base == 16) && (numstr[1] == 'x' || numstr[1] == 'X')) { + base = 16; + skip_lead = 1; + } else if ((base == 0 || base == 2) && (numstr[1] == 'b' || numstr[1] == 'B')) { + base = 2; + skip_lead = 1; } } diff --git a/ext/gmp/tests/bug50175.phpt b/ext/gmp/tests/bug50175.phpt new file mode 100644 index 0000000..0998e02 --- /dev/null +++ b/ext/gmp/tests/bug50175.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #50175: gmp_init() results 0 on given base and number starting with 0x or 0b +--FILE-- +<?php + +var_dump(gmp_init('0bcd', 16)); +var_dump(gmp_init('0xyz', 36)); + +?> +--EXPECTF-- +object(GMP)#%d (1) { + ["num"]=> + string(4) "3021" +} +object(GMP)#%d (1) { + ["num"]=> + string(5) "44027" +}

« previous php.cvs (#81375) next »