Dmitry, first of all thanks for taking a look :)
The issue in a few words - mt_rand reads arguments as long - user pass a float from the userspace - zend_parse_parameters with 'l' casts to long Here's the essential snippet echo mt_rand(0,pow(10,12)); PHP Warning: mt_rand(): max(-727379968) is smaller than min(0) So reading as long would probably not work, in the first place because the input data exceeding LONG_MAX will be corrupted by the conversion. So what I did - read input as max precision possible, no corruption - calculate as well with double - return the old way int if it's in LONG_MAX range, otherwise return float Is there a solution I don't see (or do I get your suggestion wrong)? It's just essential to get the input as precise as it can be across PHP. Besides that what could be impacts changing input arg types in this concrete case? User probably wouldn't realize that at all. Thanks Anatol On Fri, March 22, 2013 07:40, Dmitry Stogov wrote: > Hi Anatol, > > > To be honest, I didn't understand all the details of the patch :) > > > However, I see a problem: > You changed the prototype of user level rand() function to receive double > arguments instead of long. I think it's disallowed, but you may get > arguments as longs and then convert them to double. Will it work? > > > Thanks. Dmitry. > > > On Thu, Mar 21, 2013 at 9:26 PM, Dmitry Stogov <dmi...@zend.com> wrote: > > >> I'll able to look only tomorrow morning. >> >> >> Thanks. Dmitry. >> >> >> >> On Thu, Mar 21, 2013 at 8:46 PM, Anatol Belski <a...@php.net> wrote: >> >> >>> Hi Dmitry, >>> >>> >>> I developed a patch for this one >>> https://bugs.php.net/bug.php?id=64450 . >>> It's regarding to the long overflow in mt_rand(). The main idea is to >>> work with the args as double internally and then return php float if >>> it exceeds the LONG_MAX. I strived to let the old behavior to be >>> unchanged, all the older tests pass. Please take a look. >>> >>> Regards >>> >>> >>> Anatol >>> >>> >> >> > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php