From 2e079a988d477f055cfac053245d725a936f1602 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 27 Apr 2014 22:39:54 +0000 Subject: [PATCH] Make wxMSW wxTextCtrl::AdjustSpaceLimit() safe to call in all cases. Allow calling this function not only from inside DoWriteText(): first, because the existing code could be doing this (although this is only a concern in 3.0 branch as it was made private in the trunk) and second because it could actually happen if the text limit was exceeded by user typing in the control. See #15980. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76413 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/textctrl.h | 8 ++++---- src/msw/textctrl.cpp | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index f5d08060b8..11ee83bd5a 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -265,11 +265,11 @@ private: void OnKeyDown(wxKeyEvent& event); - // call this to increase the size limit (will do nothing if the current - // limit is big enough) + // Used by EN_MAXTEXT handler to increase the size limit (will do nothing + // if the current limit is big enough). Should never be called directly. // - // returns true if we increased the limit to allow entering more text, - // false if we hit the limit set by SetMaxLength() and so didn't change it + // Returns true if we increased the limit to allow entering more text, + // false if we hit the limit set by SetMaxLength() and so didn't change it. bool AdjustSpaceLimit(); DECLARE_EVENT_TABLE() diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 207b825c40..814cd7ad1b 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -2139,13 +2139,23 @@ bool wxTextCtrl::AdjustSpaceLimit() unsigned int len = ::GetWindowTextLength(GetHwnd()); if ( len >= limit ) { + unsigned long increaseBy; + // We need to increase the size of the buffer and to avoid increasing // it too many times make sure that we make it at least big enough to - // fit all the text we are currently inserting into the control. - unsigned long increaseBy = gs_lenOfInsertedText.top(); + // fit all the text we are currently inserting into the control, if + // we're inserting any, i.e. if we're called from DoWriteText(). + if ( !gs_lenOfInsertedText.empty() ) + { + increaseBy = gs_lenOfInsertedText.top(); - // Indicate to the caller that we increased the limit. - gs_lenOfInsertedText.top() = -1; + // Indicate to the caller that we increased the limit. + gs_lenOfInsertedText.top() = -1; + } + else // Not inserting text, must be text actually typed by user. + { + increaseBy = 0; + } // But also increase it by at least 32KB chunks -- again, to avoid // doing it too often -- and round it up to 32KB in any case.