Home Dashboard Directory Help
Search

CWinApp causes access violation by using uninitialized data by Frank Heimes


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 588348
Opened: 8/23/2010 6:06:11 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

CWinApp relies on the CRT to initialize its members and may therefore access uninitialized data if it is created dynamically.

At this point, we may start a discussion about whether or not it is feasible or allowed at all to instantiate the CWinApp instance statically or dynamically. The point is that it was possible to do so using VC.90 and it will be possible again if the proposed remedy mentioned below is applied.

The crash is caused by the fact that CWinApp does not initialize all members. It relies on the CRT to fill all members with 0. Since CWinApp is a class - not a value type - I consider this bad design.

Fix:
1) Explicitly initialize members in the constructor:
    m_nCmdShow = 0;
    m_pszAppID = NULL;
    m_dwPromptContext = 0;
    m_dwPolicies = _AFX_SYSPOLICY_NOTINITIALIZED;
    
2) Add m_pszAppID to CWinApp::Dump() or mark that function "DEPRECATED" if it is obsolete.

Please keep the following in mind when applying changes to MFC

1) Do not rely on the runtime to initialize static data.
Classes should always initialize all members unless that may impose a performance penalty.

2) Do not crash the application if the user does not call a public member that is not mandatory (SetAppID)

Please run the VS 2010 C++ Code Analysis at least once on your MFC sources and fix at least the very worst problems before publishing the next major MFC release.
Details
Sign in to post a comment.
Posted by Microsoft on 9/2/2010 at 10:47 AM
Hello,

Thanks for the report. This issue has been fixed in MFC for the next major release of Visual Studio.

Pat Brenner
Visual C++ Libraries Development
Posted by Microsoft on 8/23/2010 at 9:47 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Posted by Microsoft on 8/23/2010 at 9:47 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Posted by Microsoft on 8/23/2010 at 5:08 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
AddToRecentFileListCrash.zip 8/23/2010 76 KB