Jump to content

Potential division by zero in SystemC Library

Recommended Posts

Hi All,


There are many points where there are division by 0 observed and can show up any time. We have found no protection mechanism for that.


One such example  (sysc/datatypes/fx/scfx_rep.cpp) : 


     switch( numrep )

case SC_BIN:
case SC_BIN_US:
case SC_CSD:
   step = 1;
case SC_OCT:
case SC_OCT_US:
   step = 3;
case SC_HEX:
case SC_HEX_US:
   step = 4;
   step = 0;
    msb = (int) ceil( double( msb + 1 ) / step ) * step - 1;
    lsb = (int) floor( double( lsb ) / step ) * step;
    if( msb < 0 )
s += '.';
if( fmt == SC_F )
   int sign = ( b.is_neg() ) ? ( 1 << step ) - 1 : 0;
   for( int i = ( msb + 1 ) / step; i < 0; i ++ )
if numrep defaults, there will be division by zero. Functionally it never showed up, still there is a chance this will be triggered. 
We can share the complete lint report if you are interested.
Regards, Sumit

Share this post

Link to post
Share on other sites

As in the other post about dereferencing NULL pointers, I suspect that (all of?) these reports are false positives as well.


If you want to silence the linter about these, just add calls to explicitily non-returning functions like std::terminate. On the other hand, a division by zero will usually abort your simulation as well. ;-)



Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now