This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Divide by Zero segment fault
- From: Andrew Haley <aph at redhat dot com>
- To: Deepthi Bokka <dbokka at in dot autorobinc dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Wed, 17 Oct 2012 18:44:18 -0700
- Subject: Re: Divide by Zero segment fault
- References: <9843D313A3D30048BAAC430B437718BE5CDB9BE8@ADC.in.autorobinc.com>
On 10/16/2012 10:58 PM, Deepthi Bokka wrote:
> I am new to this group and I am working on a project where I am
> porting the Diab build ECU software to GCC 3.4.4 version. This
> software actually works on MPC555 series of processor but I am
> removing all the hardware dependencies and creating the exe and dll
> so that it can run on Windows XP system. The dll will run on a
> proprietary tool to simulate the results.
>
> But when I am running exe or dll, I am getting a segmentation fault
> because of divide by zero. To check for divide by zero in the
> software, code is very huge with many files and there are multiple
> places where this can occur. So checking for zero and skipping that
> is ruled out for my case.
>
> But when the diab build software is running on MPC555 we are not
> getting this issue as there the compiler is handled differently. For
> example: x = a/b where b=0 then this is processed as x=0 rather than
> giving error. So something by zero is treated as simply zero.
>
> I want similar functionality even in GCC build code, is there any
> option for doing this. I tried the flag -mno-check-zero-division in
> make file but I was getting make file error that this is not a valid
> flag. I tried using the signal handling "sigaction" but could not
> get the exact functionality as x/0 should be treated as 0.
>
> Please can any one help me how to handle this scenario, I can
> upgrade the GCC compiler version if higher versions can handle this
> issue.
Someone could probably figure out how to write a signal handler that
would do what you want, but it would be tricky and nonportable and
probably is not a good idea in any case. Any division by zero is
almost certainly a bug that you should fix, and I would urge you to do
so.
Andrew.