Menu

uninitMemberVar false positive?

2017-03-17
2017-03-17
  • Sander Bouwhuis

    Sander Bouwhuis - 2017-03-17

    I have the following class:

    // The module info structure
    struct COMMON_DLL_EXP MOD_INFO
    {
      bool             bAvailable,              // Is the module available?
                       bConnected,              // Are we connected to the database/server?
                       bDrawTextShadow;         // Should we draw a shadow on text edges?
      COLORREF         crCtrlBk,                // The colour of the background of list/text ctrls
                       crText,                  // The colour of the text
                       crTextShadow;            // The colour of the text shadows
      CPicture         picBackground,           // The module's background picture
                       picSignature,            // The module's signature picture
                      *pPicIcon,                // The pointer to the current icon
                       picIconUnsel,            // The module's icon (unselected)
                       picIconSel;              // The module's icon (selected)
      CStringResource *pStrRes;                 // The translated strings
      CUser            user;                    // The current user
      HKEY             hKeyRoot;                // The registry's root key of the config
      HWND             hWndCurrent,             // The currently active window of the module
                       hWndDefaultFocus,        // The handle of the window which gets the focus on loading/switching
                       hWndLauncher;            // The handle of the Launcher window
      MOD_STATE        state;                   // The state elements
      PIC_DRAW_MODE    eBkDrawMode;             // The background picture's drawing mode
      wstring         *pWstrDebugLog;           // The debug log
      uint16           u16Module;               // The module's bitmask
      wchar_t          pwcLibraryName[32],      // The name of the module's library ("module.dll")
                       pwcModuleName[32],       // The name of the module
                       pwcOnlineFacebook[256],  // The Facebook web address
                       pwcOnlineFeedback[256],  // The feedback web address
                       pwcOnlineHelp[256],      // The help web address
                       pwcOnlineLinkedIn[256],  // The LinkedIn web address
                       pwcOnlineTwitter[256],   // The Twitter web address
                       pwcSkinDir[MAX_PATH];    // The directory which contains the skin
    
      // Constructor
      MOD_INFO()
      {
        try
        {
          CHECK_MEM_LEAKS
    
          // Clear the variables
          bAvailable       = false;
          bConnected       = false;
          bDrawTextShadow  = false;
          crCtrlBk         = COLOUR_UNDEFINED;
          crText           = COLOUR_UNDEFINED;
          crTextShadow     = COLOUR_UNDEFINED;
          eBkDrawMode      = PIC_DRAW_MODE::dm_normal;
          hKeyRoot         = NULL;
          hWndCurrent      = NULL;
          hWndDefaultFocus = NULL;
          hWndLauncher     = NULL;
          pPicIcon         = nullptr;
          pStrRes          = nullptr;
          pWstrDebugLog    = nullptr;
          u16Module        = NULL;
          memset(pwcLibraryName,    NULL, sizeof(pwcLibraryName));
          memset(pwcModuleName,     NULL, sizeof(pwcModuleName));
          memset(pwcOnlineFacebook, NULL, sizeof(pwcOnlineFacebook));
          memset(pwcOnlineFeedback, NULL, sizeof(pwcOnlineFeedback));
          memset(pwcOnlineHelp,     NULL, sizeof(pwcOnlineHelp));
          memset(pwcOnlineLinkedIn, NULL, sizeof(pwcOnlineLinkedIn));
          memset(pwcOnlineTwitter,  NULL, sizeof(pwcOnlineTwitter));
          memset(pwcSkinDir,        NULL, sizeof(pwcSkinDir));
        }
        catch(...) { OnException(__FILE__, __LINE__, __FUNCSIG__, __TIMESTAMP__, nullptr); }
      }
    
      // The destructor
     ~MOD_INFO()
      {
        try
        {
          CHECK_MEM_LEAKS
    
          // Free the resources
          SAFE_CLOSE_HANDLE(state.hEvtState);
        }
        catch(...) { OnException(__FILE__, __LINE__, __FUNCSIG__, __TIMESTAMP__, nullptr); }
      }
    };
    

    I get this warning:
    Member variable 'MOD_INFO::bAvailable' is not initialized in the constructor.

    The member is literally the FIRST parameter that is initialized! Is this a false positive, or am I missing something?

     
  • Daniel Marjamäki

    It seems to me that you have more or less:

    CHECK_MEM_LEAKS bAvailable = false;

    It looks like a variable declaration: XYZ someName = false;

    That probably confuses Cppcheck. Cppcheck doesn't care if there are newlines.

     

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.