c - SIGFPE with gcc and unsigned integers -


i'm getting weird behaviour executable compiled different versions of gcc, emit sigfpe signal , best part have no floating point of kind in code; if shed light on ... literally don't know start debug this, it's weird , bug triggered gcc installations have 4.9 6.0.

here snippet reproduces problem

// floating point exception - sigfpe #include <stdio.h> typedef unsigned int t; int main() { #define n 256    (t = 0; < n; ++i)     {       += (i % i);       printf("%u\t", i);     } } // bug uncovered // gcc version 4.9.2 (debian 4.9.2-10) // gcc version 5.1.0 (gcc) // gcc version 6.0.0 20150517 (experimental) (gcc) // using -std=c11 or -std=c99 

the purpose of code reproduce problem, know logic of doesn't make sense ( modulo part ) clang passes test, no version of gcc same , know why if there technical explanation kind of behaviour .

after running code, under cygwin, gdb dumped trace.

$ cat sigfpe.exe.stackdump exception: status_integer_divide_by_zero @ rip=00100401115 rax=0000000000000000 rbx=000000000022cb20 rcx=0000000000000001 rdx=0000000000000000 rsi=000000060003a2f0 rdi=0000000000000000 r8 =0000000000000000 r9 =0000000000000000 r10=0000000000230000 r11=0000000000000002 r12=0000000000000000 r13=0000000000000001 r14=000000000022cb63 r15=000000000022cb64 rbp=000000000022cad0 rsp=000000000022caa0 program=c:\cygwin64\home\luser\sigfpe.exe, pid 6808, thread main cs=0033 ds=002b es=002b fs=0053 gs=002b ss=002b stack trace: frame        function    args 0000022cad0  00100401115 (00000000020, 30001000000ff00, 0018004830f, 0000022d680                                                                                                                ) 0000022cbc0  00180048380 (00000000000, 00000000000, 00000000000, 00000000000) 00000000000  0018004607c (00000000000, 0003e704021, 00000000000, 0000000002d) 00000000000  00180046114 (00000000000, 00000000000, 00000000000, 00000000000) 00000000000  00100401191 (00000000000, 00000000000, 00000000000, 00000000000) 00000000000  00100401010 (00000000000, 00000000000, 00000000000, 00000000000) 00000000000  000772e59cd (00000000000, 00000000000, 00000000000, 00000000000) 00000000000  0007741b981 (00000000000, 00000000000, 00000000000, 00000000000) end of stack trace 

the clue in operation i += (i % i)

when loop initial value of 0, of course, divide 0 error.

have tried catch signal?

look @ c11 standard on page 265, sigfpe - an erroneous arithmetic operation, such 0 divide or operation resulting in overflow

it not compiler bug, implementation defined.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -