From 8b3b778f3d9f18c780d8fca95eaee7a24694ee3c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 12 Apr 2000 23:38:20 +0000 Subject: [PATCH] wxTextCtrl::GetLineText() fixes: a) doesn't crash b) more efficient c) works in Unicode mode git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7145 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/textctrl.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 584bcb4c39..b763b0a7a7 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -810,24 +810,20 @@ int wxTextCtrl::GetLineLength(long lineNo) const wxString wxTextCtrl::GetLineText(long lineNo) const { - // TODO this should probably be optimized by using GetWriteBuf() - size_t len = (size_t)GetLineLength(lineNo) + 1; - if ( len < sizeof(WORD) ) - { - // there must be at least enough place for the length WORD in the - // buffer - len += sizeof(WORD); - } - char *buf = (char *)malloc(len); + // there must be at least enough place for the length WORD in the + // buffer + len += sizeof(WORD); + + wxString str; + wxChar *buf = str.GetWriteBuf(len); + *(WORD *)buf = len; - int noChars = (int)SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf); - buf[noChars] = 0; + len = (size_t)::SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf); + buf[len] = 0; - wxString str(buf); - - free(buf); + str.UngetWriteBuf(len); return str; }