Re: Re: gmp_init with a base argument
| From: | Troels Arvin | Date: | Sun, 05 Aug 2001 11:46:21 +0000 |
| Subject: | Re: Re: gmp_init with a base argument | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-62138@lists.php.net to get a copy of this message | ||
On Thu, 02 Aug 2001 19:16:26 +0200, "Stanislav Malyshev" <stas@zend.com>
wrote:
> TA>> By the way:
> TA>> I think that the decbin() function should bail out if you pass it
> a TA>> value which contains more bits than PHP is able to handle. -
> Perhaps TA>> with a hint about using GMP for large numbers.
>
> I'd say "give a warning" istead of "bail out", but that's a good
> idea,
> generally.
OK. Here is a suggestion for an adjustment in math.c. The patch could
probably be improved: The check for strings with more than 31 chars
should probably be less hard-coded, but I'm not sure which contant to
use for determining maximum size of a LONG.
/Troels
--- php4-orig/ext/standard/math.c Sun Aug 5 12:51:38 2001
+++ php4/ext/standard/math.c Sun Aug 5 12:52:35 2001
@@ -813,6 +813,11 @@
}
convert_to_string_ex(arg);
+
+ if ((*arg)->value.str.len > 31) {
+ php_error(E_WARNING, "bindec: input string too long (max is a 31-bit value)");
+ }
+
ret = _php_math_basetolong(*arg, 2);
RETVAL_LONG(ret);