nHash>0...">

Xcode C code, parser "divide by zero" issue

I have a C file containing the following piece of code inside a function:

assert( pCache->nHash>0 && pCache->apHash );
...
if( pPage ){
    unsigned int h = iKey % pCache->nHash; 
...

      

When I run Analyze, Xcode throws a logical error - division by zero on the last line containing the module operation.

If I add an extra check, if so, then the error goes away:

if( pPage && pCache->nHash>0 ){

      

Shouldn't a statement containing pCache->nHash>0

, avoid divisions by zero, which in turn?

+3


source to share


1 answer


Assertions are most often used only in development. When you create the final release, you turn off approvals.

It is argued that there are logical errors that must be corrected / verified by the developer. They are not used as an actual check for your program logic.



This explains why you should add an if statement that checks if your variable is greater than 0. The parser analyzes your code and most likely ignores the assertions, since you must remove them during the final build.

+3


source







All Articles