Bug #1335: modulus operator overflows

From: Date: Tue, 20 Apr 1999 18:27:57 +0000
Subject: Bug #1335: modulus operator overflows
Groups: php.dev 
Request: Send a blank email to php-dev+get-5155@lists.php.net to get a copy of this message
From: cclarke@netcom.com Operating system: Linux PHP version: 3.0.7 PHP Bug Type: Misbehaving function Bug description: modulus operator overflows Sample code: $number = 116503231466; print $number / 1000; print $number % 1000; The first print statement will print: 1150321.466 The second print statement will print: -648 instead of the expected 466. Looking at the code in operators.c, div_function calls convert_string_to_number() which promotes $number to double because strtol() returns ERANGE. Then div_function then performs a floating point divide. mod_function, however calls convert_to_long, which calls convert_to_long_base(), which ignores the ERANGE error, returning LONG_MIN on Linux. I think mod_function() should be using convert_string_to_number(), and case out the code depending on the data type of the numbers. I don't know what else uses convert_to_long() and/or convert_to_long_base(), so I don't know if these functions need to be returning a range error, though silently returning LONG_MIN seems dangerous. I'm happy to take a shot at rewriting mod_function() if that would be useful. Thanks, -Cam -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#5155) next »