Menu

Arithmetical defect in cppcheck

2019-10-26
2021-01-27
  • Jaroslav Fojtik

    Jaroslav Fojtik - 2019-10-26

    These messsages are complete nonsense:
    Argument 'NumS+2' to function atoi is always 3
    Assuming that condition 'NumS==NULL' is not redundant
    Argument 'NumS+2' to function atoi is always 3

    The NumS is string obtained from external variable Cmb_Select->Text. And shifting 2 characters from beginning could produce completely different input.

    //---------------------------------------------------------------------------
    void __fastcall TFPIDguard::Cmb_SelectChange(TObject *Sender)
    {
     AnsiString Str = Cmb_Select->Text;
     const char *NumS = strstr(Str.c_str(), " #");
     if(NumS == NULL) return;
    
     int PidHookId = atoi(NumS+2);
    
     if(DtpCom!=NULL && MarshPidG!=NULL)
     {
       if(!EditToFloat(Edit_wCrit, 1)) return;
       if(!EditToInt(Edit_t_Crit, 1)) return;
    
       int result = DtpCom->ReadMarshalledDatapoolItem(*MarshPidG,PidGuardIndex);
       if(result<0)
       {
         AnsiString errs;
         errs.printf(_("Cannot read data from object #%d, error %d."), PidGuardIndex, result);
         MessageErr(errs);
         return;
       }
    
     
  • CHR

    CHR - 2021-01-26

    No repro with v2.3, except for style: Variable 'PidHookId' is assigned a value that is never used. [unreadVariable], which is correct.

     
  • Jaroslav Fojtik

    Jaroslav Fojtik - 2021-01-27

    Yes, you are right, the problem seems to disappear after 2 years ;).

     

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.