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
Link to comment
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. ;-)



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...