Re: Divide by zero detection

Hans-Peter Diettrich <>
Thu, 20 Sep 2007 12:27:01 +0200

          From comp.compilers

Related articles
Divide by zero detection ( (2007-09-18)
Re: Divide by zero detection (Hans-Peter Diettrich) (2007-09-20)
Re: Divide by zero detection (Alex Colvin) (2007-09-21)
Re: Divide by zero detection (George Neuner) (2007-09-22)
Re: Divide by zero detection (Gene) (2007-09-24)
| List of all articles for this month |

From: Hans-Peter Diettrich <>
Newsgroups: comp.compilers
Date: Thu, 20 Sep 2007 12:27:01 +0200
Organization: Compilers Central
References: 07-09-074
Keywords: arithmetic, analysis, comment
Posted-Date: 20 Sep 2007 21:37:20 EDT wrote:

> I am looking for tools able to detect inside the source code,
> potential divide by zero errors. Does it exist. For what languages,
> what platform ? Thanks for your help

What's wrong with this approach:

1) find all divisions
2) exclude those with a constant non-zero right hand side

The interpretation of "division" and "non-zero RHS" depends on your


3) exclude those with a preceding check for a non-zero RHS
4) exclude those with a handled zero-divide error

Again "check" and "handled" depends on your language.

[You can do better than that, e.g.

  a = 42;;
  b = c/a;

No zero divide there, either. Doing the analysis properly is doubtless
undecidable, but with aggressive dataflow analysis you should be able to
rule out a lot of known non-zero divisors. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.