Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Memory bug in XTPMarkupStatic
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Memory bug in XTPMarkupStatic

 Post Reply Post Reply
Author
Message
DavidH View Drop Down
Groupie
Groupie


Joined: 24 March 2007
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote DavidH Quote  Post ReplyReply Direct Link To This Post Topic: Memory bug in XTPMarkupStatic
    Posted: 2 hours 7 minutes ago at 4:08pm
In Source/Controls/Static/XTPMarkupStatic.cpp, a growing buffer is not reallocated correctly.

template<class T>
AFX_INLINE BOOL XTPStrPushChr(T*& pStr, T ch, SIZE_T& nPos, SIZE_T& nSize)
{
    if (NULL == pStr)
    {
        nSize = 0x100;
        pStr  = (T*)malloc(nSize * sizeof(T));
        if (NULL == pStr)
            return FALSE;

        *pStr = T('\0');
        nPos  = 0;
    }

    pStr[nPos] = ch;
    if (++nPos == nSize)
    {
        nSize *= 2;
   // --->>>>     pStr = (T*)realloc(pStr, nSize);
   // Should be:
        pStr = (T*)realloc(pStr, nSize * sizeof(T));
        if (NULL == pStr)
            return FALSE;

        pStr[nPos] = T('\0');
    }

    return TRUE;
}
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.063 seconds.