[PATCH] Fix bug 3269 - Crashing on printing (win)

From: Johnny Lee (typo_pl@hotmail.com)
Date: Fri Feb 14 2003 - 01:44:19 EST

  • Next message: Johnny Lee: "[PATCH] typo in abi\src\wp\impexp\xp\ie_imp_RTF.cpp"

    I grabbed the tarball for abiword.1.0.4 and compiled with MSVC6.

    After much futzing, I was able to get the thing to build a debug version of
    AbiWord.

    I was able to locate the problem by chance when the app AV'd on the ResetDC
    call below.

    The cause of the problem is that the DEVMODE struct is not completely
    initialized. Windows (maybe GDI or the printer driver) is looking at some of
    the uninitialized fields and crapping out.

    That's why printing works for some people and not for others. It depends on
    what's on the stack where DEVMODE is accessed. A pseudo-random crapshoot.

    The simplest, comprehensive fix is listed below.

    The specific fix is the dmDeviceName field needs to be set to an empty
    string, i.e dmDeviceName[0] = 0;

    If I use the patch listed below, I can print 5 out of 5 times without
    crashes.

    If I set the entire dmDeviceName field in the DEVMODE struct to 0xFF (to
    guarantee garbage data in the DEVMODE dmDeviceName field), I get crashes, as
    per bug 3269, 5 out of 5 times.

    I'm not sure if there are other problems lurking if you do not zero-init the
    whole DEVMODE struct.

    The MS SDK docs for DEVMODE say that the dmSpecVersion field should be set
    to DM_SPECVERSION. So I've added that in too.

    Minor style nit: MS Hungarian would call the DEVMODE struct 'devmode', not
    'pDevMode'. The initial 'p' would indicate that this var was a pointer to
    something, which it isn't.

    --- gr_Win32Graphics.cpp.old Thu Feb 13 22:33:45 2003
    +++ gr_Win32Graphics.cpp Fri Feb 14 00:58:37 2003
    @@ -653,16 +653,18 @@
    {
            if (m_bStartPage)
            {
                    EndPage(m_hdc);
            }

            // Correct for Portrait vs Lanscape mode
            DEVMODE pDevMode;
    + memset(&pDevMode, 0, sizeof(pDevMode));
    + pDevMode.dmSpecVersion = DM_SPECVERSION;
            pDevMode.dmSize = sizeof(DEVMODE);
            pDevMode.dmDriverExtra = 0;
            pDevMode.dmFields = DM_ORIENTATION;
            pDevMode.dmOrientation = (bPortrait) ? DMORIENT_PORTRAIT :
    DMORIENT_LANDSCAPE;
            ResetDC( m_hdc, &pDevMode );

            const int iRet = StartPage(m_hdc);

    _________________________________________________________________
    MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
    http://join.msn.com/?page=features/virus



    This archive was generated by hypermail 2.1.4 : Fri Feb 14 2003 - 01:48:32 EST