Menu

Float comparison false positive deffect

2021-01-27
2021-01-30
  • Jaroslav Fojtik

    Jaroslav Fojtik - 2021-01-27

    Please note that extent of float type is much more higher than 0xFFFFFFFFFFFFFFFF.
    Your false positive is a complete nonsense. The condition is apparently not always true.

    CWE: 571
    Condition 'ff>0xFFFFFFFFFFFFFFFF' is always true

    /** Write float valur to datapool  variant. The variant type is resolved internally. */
    void DatapoolVariant::SetAsFloat(float ff)
    {    
     if(size>1)
      {
        if(pVoid==NULL) return;
        switch(type)
        {
         case 'Q': if(ff<0)          {*ArrQ=0;break;}
                    if(ff>0xFFFFFFFFFFFFFFFF) {*ArrQ=0xFFFFFFFFFFFFFFFF;break;}
                    *ArrQ = (UINT64)ff; 
                    break;
          case 'q': *Arrq = (INT64)ff; 
                     break;
    
     
  • CHR

    CHR - 2021-01-30

    I can reproduce with this snippet:

    void SetAsFloat(float ff, char type)
    {    
        switch(type)
        {
         case 'Q': if(ff<0)                  {*ArrQ=0;break;}
                   if(ff>0xFFFFFFFFFFFFFFFF) {*ArrQ=0xFFFFFFFFFFFFFFFF;break;}
                   break;
        }
    }
    

    This seems to be an instance of this problem: https://trac.cppcheck.net/ticket/10150

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.