Re: Overflow exception
| From: | Curt Zirzow | Date: | Sat, 27 May 2000 17:18:42 +0000 |
| Subject: | Re: Overflow exception | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-19623@lists.php.net to get a copy of this message | ||
php will core dump (SIGFPE) in the following conditions:
Any time a op->value.dval <= -2147483649 or >= 2147483648 and
it is converted to long as such:
op->value.lval = (long) op->value.dval;
I've got two ways to fix this:
check to see if it is out of range and return without the
conversion spewing out a warning.
or
trap the SIGFPE by using signal(SIGFPE, handler) let the bits
get lost and spew out a warning.
Of course there may be other ways of fixing the problem.
Any ideas?
Curt
* Curt Zirzow (curt@zirzow.org) [000524 14:45]:
> This is related to bug #2962 but I've narrowed it down to it
> affecting all conversions from a double to int where there
> is a overflow exception.
>
>
> FreeBSD 3.2
> Php 4.0.0
> Apache/1.3.9
>
> <?
> $var = 2147483647+1; //or < -2147483648
> echo $var."<br>\n";
> settype($var, 'string'); //removing this makes a SIGFPE
> settype($var, 'integer');
> settype($var, 'double');
> echo $var."<br>\n"; //overflow!!
>
> ?>
>
> Program received signal SIGFPE, Arithmetic exception.
> 0x809cbea in convert_to_long_base (op=0x821358c, base=10)
> at zend_operators.c:203
> 203 op->value.lval = (long) op->value.dval;
> (gdb) backtrace
> #0 0x809cbea in convert_to_long_base (op=0x821358c, base=10)
> at zend_operators.c:203
> #1 0x809cb95 in convert_to_long (op=0x821358c) at zend_operators.c:185
> #2 0x80c3079 in php_if_settype (ht=2, return_value=0x82135ac, this_ptr=0x0,
> return_value_used=0) at basic_functions.c:1057
> #3 0x80f82fd in execute (op_array=0x8211e0c) at ./zend_execute.c:1574
> #4 0x8090b29 in php_execute_script (primary_file=0xbfbfd5d0) at main.c:1200
> #5 0x80a9c3d in apache_php_module_main (r=0x821a034, fd=30,
> display_source_mode=0) at sapi_apache.c:93
> #6 0x808d18e in send_php ()
> #7 0x808d1d0 in send_parsed_php ()
> #8 0x8117f7b in ap_invoke_handler ()
> #9 0x812aa01 in process_request_internal ()
> #10 0x812aa60 in ap_process_request ()
> #11 0x81224a9 in child_main ()
> #12 0x8122634 in make_child ()
> #13 0x812278f in startup_children ()
> #14 0x8122d40 in standalone_main ()
> #15 0x8123593 in main ()
> #16 0x8060829 in _start ()
--
Any time things appear to be going better, you have overlooked
something.