|  | 
| CXTPSyntaxEditCtrl::OnGetText(WPARAM wBuff | 
| Post Reply   | 
| Author | |
| canyou   Newbie   Joined: 18 June 2010 Status: Offline Points: 4 |  Post Options  Thanks(0)  Quote  Reply  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. | |
|  | |
| Oleg   Senior Member   Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |  Post Options  Thanks(0)  Quote  Reply  Posted: 18 June 2010 at 6:36am | 
| 
   Hi,
 Try to pass larger buffer and larger wBufferSize. | |
| 
     Oleg, Support Team CODEJOCK SOFTWARE SOLUTIONS | |
|  | |
| canyou   Newbie   Joined: 18 June 2010 Status: Offline Points: 4 |  Post Options  Thanks(0)  Quote  Reply  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. | |
|  | |
| canyou   Newbie   Joined: 18 June 2010 Status: Offline Points: 4 |  Post Options  Thanks(0)  Quote  Reply  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 ? | |
|  | |
| Smucker   Senior Member     Joined: 02 February 2008 Status: Offline Points: 156 |  Post Options  Thanks(0)  Quote  Reply  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) | |
|  | |
| Oleg   Senior Member   Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |  Post Options  Thanks(0)  Quote  Reply  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 | |
|  | |
| canyou   Newbie   Joined: 18 June 2010 Status: Offline Points: 4 |  Post Options  Thanks(0)  Quote  Reply  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. | |
|  | |
| Post Reply   | |
| Tweet | 
| Forum Jump | Forum Permissions  You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |