Bug 7604

Summary: Floating point exception - Fuzz Testing
Product: Busybox Reporter: Fernando Muñoz <fernando>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: 1.21.x   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:

Description Fernando Muñoz 2014-11-06 20:25:29 UTC
Following code generates Floating point exception:

echo $(( 2**63 % -1 ))

I don't have debug symbols installed at the moment, sorry.

Reading symbols from busybox...(no debugging symbols found)...done.
(gdb) run sh -c 'echo $(( 2**63 % -1 ))'
Starting program: /bin/busybox sh -c 'echo $(( 2**63 % -1 ))'

Program received signal SIGFPE, Arithmetic exception.
0x0000000000423b85 in ?? ()


This exception only appear on 64 bits apparently, tried on 32 bits but it didn't occur.
Comment 1 Denys Vlasenko 2014-11-18 13:34:04 UTC
The same happens in bash.

The cause is that MAX_NEGATIVE_INT / -1 = MAX_POSITIVE_INT+1 and thus is not representable. Therefore these ops fail:

                        rez /= right_side_val;

                        rez %= right_side_val;

They dont fail in 32-bit case because 64-bit wide divide in 32-bit case is handled as a several divides of smaller width. The result is wrong, though (since correct result is not representable),

Fixed in git. Thanks!