Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Syntax Edit
  New Posts New Posts RSS Feed - CXTPSyntaxEditCtrl::OnGetText(WPARAM wBuff
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPSyntaxEditCtrl::OnGetText(WPARAM wBuff

 Post Reply Post Reply
Author
Message
canyou View Drop Down
Newbie
Newbie


Joined: 18 June 2010
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote canyou Quote  Post ReplyReply Direct Link To This Post Topic: CXTPSyntaxEditCtrl::OnGetText(WPARAM wBuff
    Posted: 18 June 2010 at 5:42am
What is this function??

LRESULT CXTPSyntaxEditCtrl::OnGetText(WPARAM wBufferSize, LPARAM lpBuffer)


In my desktop, MDITextEditor.exe died in this code.
If i selected some string, died App.
In the callstack........

STRNCPY_S(pDest, wBufferSize, (LPCTSTR)pTextData, wBufferSize);

#if (_MSC_VER > 1310) // VS2005
     _tcsncpy_s(strDestination, sizeInWords, strSource, count);


died this code => _RETURN_BUFFER_TOO_SMALL(_DEST, _SizeInBytes);


Please help me.!!! Thanks.
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 18 June 2010 at 6:36am
Hi,
Try to pass larger buffer and larger wBufferSize.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
canyou View Drop Down
Newbie
Newbie


Joined: 18 June 2010
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote canyou Quote  Post ReplyReply Direct Link To This Post Posted: 21 June 2010 at 1:33am
This function is called when i selected some string in editor. => ON_MESSAGE(WM_GETTEXT, OnGetText), CXTPSyntaxEditCtrl::OnGetText
That may be system call.
 
So, i think..that function have some unstable code.
 
For example, wBufferSize > tcslen(lpBuffer)
 
WPARAM wBufferSize = 255;
TCHAR lpBuffer= new TCHAR[200];
SendMessage( WM_GETTEXT, wBufferSize, lpBuffer);
 
LRESULT CXTPSyntaxEditCtrl::OnGetText(WPARAM wBufferSize, LPARAM lpBuffer) {
         LPTSTR pDest = (LPTSTR)lpBuffer;
        STRNCPY_S(pDest, wBufferSize, (LPCTSTR)pTextData, wBufferSize);   // <== died 'Buffer Too Small'
}
 
 
How can i exception handling about this error?
Is this user fault ? I want to handling this error.
Back to Top
canyou View Drop Down
Newbie
Newbie


Joined: 18 June 2010
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote canyou Quote  Post ReplyReply Direct Link To This Post Posted: 21 June 2010 at 3:29am

I tested this case using by MDITextEditor Application.

First testcase........................
1. void CMDITextEditorView::OnReadOnly() {
 TCHAR buffer[255];
 GetEditCtrl().GetWindowText( buffer, 255 );          // <== This code generated event, [CXTPSyntaxEditCtrl, ON_MESSAGE(WM_GETTEXT, OnGetText)]
}
 
2. Compile and App execution
 
3. write text at editor( more than 256 Char )
 
4. Execute Testing Code
   => Application Menu > Edit > Read Only
 
5. This case application died.
LRESULT CXTPSyntaxEditCtrl::OnGetText(WPARAM wBufferSize, LPARAM lpBuffer) {
...
STRNCPY_S(pDest, wBufferSize, (LPCTSTR)pTextData, wBufferSize);      // died this code => _RETURN_BUFFER_TOO_SMALL(_DEST, _SizeInBytes); 
...
}
 
Is this case   USER FAULT or Bad Code???
 
 
 
Second testcase........................
I changed only first step.
 
1. void CMDITextEditorView::OnReadOnly() {
 TCHAR buffer[255];
 GetEditCtrl().GetWindowText( buffer, 200);          // <== This code generated event, [CXTPSyntaxEditCtrl, ON_MESSAGE(WM_GETTEXT, OnGetText)]
}
 
Application died like first testcase.
 
 
 
 
So, i'm finding solution.
[1] LRESULT CXTPSyntaxEditCtrl::OnGetText(WPARAM wBufferSize, LPARAM lpBuffer)
{
 if (wBufferSize == 0)
  return OnGetTextLen(0, 0);
  wBufferSize = -1;                      // <== add this code, so..application not died. very big size buffer
 
.............
}
 
[2] LRESULT CXTPSyntaxEditCtrl::OnGetText(WPARAM wBufferSize, LPARAM lpBuffer)
{
.............
//STRNCPY_S(pDest, wBufferSize, (LPCTSTR)pTextData, wBufferSize);            // <== Not use this code.
_tcsncpy(pDest, (LPCTSTR)pTextData, wBufferSize);
}
 
can be solution ?
Back to Top
Smucker View Drop Down
Senior Member
Senior Member
Avatar

Joined: 02 February 2008
Status: Offline
Points: 156
Post Options Post Options   Thanks (0) Thanks(0)   Quote Smucker Quote  Post ReplyReply Direct Link To This Post Posted: 21 June 2010 at 9:21am
Setting wBufferSize to -1 will overrun the buffer. I think this is better, it will keep you from overrunning buffer but return as much as possible:

STRNCPY_S(pDest, wBufferSize, (LPCTSTR)pTextData, _TRUNCATE);

Product: Xtreme Toolkit Pro version 13.2 (Unicode, static build)

Platform: Windows 200x/XP/Vista/Win7 (32/64 bit)

Language: Visual C++ 9.0 (Studio 2008)

Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 21 June 2010 at 9:21am
Thanks, agree.

Please replace to
STRNCPY_S(pDest, wBufferSize, (LPCTSTR)pTextData, wBufferSize - 1);
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
canyou View Drop Down
Newbie
Newbie


Joined: 18 June 2010
Status: Offline
Points: 4
Post Options Post Options   Thanks (0) Thanks(0)   Quote canyou Quote  Post ReplyReply Direct Link To This Post Posted: 21 June 2010 at 8:46pm
Smucker and oleq very thanks. Your answer is best solution. But, It may have some bug by side effect.
STRNCPY_S(pDest, wBufferSize, (LPCTSTR)pTextData, wBufferSize-1 );    <== It's OK.
STRNCPY_S(pDest, wBufferSize, (LPCTSTR)pTextData, _TRUNCATE);         <== It's OK.

 
And this comment from MSDN :

If truncation behavior is needed, use _TRUNCATE or (size – 1):

strncpy_s(dst, 5, "a long string", _TRUNCATE);

strncpy_s(dst, 5, "a long string", 4);

 

Thanks. And i hope to fixed SyntaxEditor's bug.
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.172 seconds.