Fix a dangling pointer issue concerning the text input.

patch reviewed by vexed.

fixes ticket:1480
Thanks to the excellent detective work by Ai_Tak !


git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@9784 4a71c877-e1ca-e34f-864e-861f7616d084
master
Buginator 2010-02-13 02:01:52 +00:00 committed by Git SVN Gateway
parent aeaab52615
commit c2fc183703
1 changed files with 9 additions and 8 deletions

View File

@ -143,15 +143,15 @@ void editBoxInitialise(W_EDITBOX *psWidget)
/* Insert a character into a text buffer */
static void insertChar(utf_32_char **pBuffer, size_t *pBufferAllocated, UDWORD *pPos, utf_32_char ch)
static void insertChar(utf_32_char **pBuffer, size_t *pBufferAllocated, UDWORD *pPos, utf_32_char ch, W_EDITBOX *psWidget)
{
utf_32_char *pSrc, *pDest;
UDWORD len, count;
if (ch == '\0') return;
ASSERT( *pPos <= utf32len(*pBuffer),
"insertChar: Invalid insertion point" );
ASSERT( *pPos <= utf32len(*pBuffer), "Invalid insertion point" );
ASSERT_OR_RETURN ( , psWidget, "No widget to modify?");
len = utf32len(*pBuffer);
@ -164,7 +164,8 @@ static void insertChar(utf_32_char **pBuffer, size_t *pBufferAllocated, UDWORD *
debug(LOG_ERROR, "Couldn't realloc() string?");
return;
}
*pBuffer = newBuffer;
// update old pointer from the widget
psWidget->aText = *pBuffer = newBuffer;
*pBufferAllocated *= 2;
}
@ -183,7 +184,7 @@ static void insertChar(utf_32_char **pBuffer, size_t *pBufferAllocated, UDWORD *
/* Put a character into a text buffer overwriting any text under the cursor */
static void overwriteChar(utf_32_char **pBuffer, size_t *pBufferAllocated, UDWORD *pPos, utf_32_char ch)
static void overwriteChar(utf_32_char **pBuffer, size_t *pBufferAllocated, UDWORD *pPos, utf_32_char ch, W_EDITBOX *psWidget)
{
UDWORD len;
@ -197,7 +198,7 @@ static void overwriteChar(utf_32_char **pBuffer, size_t *pBufferAllocated, UDWOR
if (*pPos == len)
{
// At end of string.
insertChar(pBuffer, pBufferAllocated, pPos, ch);
insertChar(pBuffer, pBufferAllocated, pPos, ch, psWidget);
return;
}
@ -528,11 +529,11 @@ void editBoxRun(W_EDITBOX *psWidget, W_CONTEXT *psContext)
/* Dealt with everything else this must be a printable character */
if (editState == WEDBS_INSERT)
{
insertChar(&pBuffer, &pBufferAllocated, &pos, unicode);
insertChar(&pBuffer, &pBufferAllocated, &pos, unicode, psWidget);
}
else
{
overwriteChar(&pBuffer, &pBufferAllocated, &pos, unicode);
overwriteChar(&pBuffer, &pBufferAllocated, &pos, unicode, psWidget);
}
/* Update the printable chars */