Bug in MFC 7.1 
Author Message
 Bug in MFC 7.1

Here's another bug I happened across in MFC 7.1:

BOOL CDialogTemplate::SetSystemFont(WORD wSize)
{
    LPCTSTR pszFace = _T("System");
    WORD wDefSize = 10;
    HFONT hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
    if (hFont == NULL)
        hFont = (HFONT)::GetStockObject(SYSTEM_FONT);
    if (hFont != NULL)
    {
        LOGFONT lf;
        if (::GetObject(hFont, sizeof(LOGFONT), &lf) != 0)
        {
            pszFace = lf.lfFaceName;    // <== BUG HERE ==
            HDC hDC = ::GetDC(NULL);
            if (lf.lfHeight < 0)
                lf.lfHeight = -lf.lfHeight;
            wDefSize = (WORD)MulDiv(lf.lfHeight, 72, GetDeviceCaps(hDC,
LOGPIXELSY));
            ::ReleaseDC(NULL, hDC);
        }
    }

    if (wSize == 0)
        wSize = wDefSize;

    return SetFont(pszFace, wSize);

Quote:
}

Clearly, lf has gone out of scope by the time pszFace is used in the return
statement.  I don't expect it will be fixed, as the release date is only 3
months away, sigh, so I'll leave the solution as an exercise for Microsoft.

Keith MacDonald



Mon, 27 Jun 2005 18:41:26 GMT  
 Bug in MFC 7.1
Thank you very much for your reporting.
--------------------

::Subject: Bug in MFC 7.1
::Date: Thu, 9 Jan 2003 10:41:26 -0000
::Lines: 37
::X-Priority: 3
::X-MSMail-Priority: Normal
::X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
::X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

::Newsgroups: microsoft.public.dotnet.languages.vc
::NNTP-Posting-Host: host213-1-147-32.in-addr.btopenworld.com 213.1.147.32
::Path: cpmsftngxa09!TK2MSFTNGP08!TK2MSFTNGP09
::Xref: cpmsftngxa09 microsoft.public.dotnet.languages.vc:19094
::X-Tomcat-NG: microsoft.public.dotnet.languages.vc
::
::Here's another bug I happened across in MFC 7.1:
::
::BOOL CDialogTemplate::SetSystemFont(WORD wSize)
::{
::    LPCTSTR pszFace = _T("System");
::    WORD wDefSize = 10;
::    HFONT hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
::    if (hFont == NULL)
::        hFont = (HFONT)::GetStockObject(SYSTEM_FONT);
::    if (hFont != NULL)
::    {
::        LOGFONT lf;
::        if (::GetObject(hFont, sizeof(LOGFONT), &lf) != 0)
::        {
::            pszFace = lf.lfFaceName;    // <== BUG HERE ==
::            HDC hDC = ::GetDC(NULL);
::            if (lf.lfHeight < 0)
::                lf.lfHeight = -lf.lfHeight;
::            wDefSize = (WORD)MulDiv(lf.lfHeight, 72, GetDeviceCaps(hDC,
::LOGPIXELSY));
::            ::ReleaseDC(NULL, hDC);
::        }
::    }
::
::    if (wSize == 0)
::        wSize = wDefSize;
::
::    return SetFont(pszFace, wSize);
::}
::
::Clearly, lf has gone out of scope by the time pszFace is used in the
return
::statement.  I don't expect it will be fixed, as the release date is only 3
::months away, sigh, so I'll leave the solution as an exercise for
Microsoft.
::
::Keith MacDonald
::
::
::

This posting is provided "AS IS" with no warranties, and confers no rights.



Mon, 27 Jun 2005 21:25:33 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Unfixed bugs in MFC 7.1

2. FYI: Bug in MFC 7.1 when opening a document from the shell (VS.Net 2003 latest beta)

3. MFC 7.1 bug?

4. MFC 7.1 BUG: Shell open DDE support broken

5. two possible bugs in 7.1

6. Nasty (linker?) bug with 7.1, and friend templates

7. VC 7.1 Macro bug!

8. Bug in Visual C++ 7.1 Final Beta compiler.

9. VC 7.1 final beta: bug with template template parameters

10. Bug in ATLHTTP.H in NTLM authentication (ATL 7.0 and 7.1)

11. possible compiler bug in VC 7.1

12. C2689 bug: is it fixed in 7.1?

 

 
Powered by phpBB® Forum Software