From 6f46510c80f749df76d49f7eb8350d13aa3aecbf Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 20 Jan 2012 22:11:44 +0000 Subject: [PATCH 1/1] Add error checking when retrieving client data from wxMSW wxListBox. Verify if retrieving client data failed which might happen if the index is invalid for example. This makes code more robust and also consistent with wxChoice. Closes #13883. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70415 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/listbox.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index 69565096f7..fd17da4b41 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -306,7 +306,15 @@ bool wxListBox::IsSelected(int N) const void *wxListBox::DoGetItemClientData(unsigned int n) const { - return (void *)SendMessage(GetHwnd(), LB_GETITEMDATA, n, 0); + LPARAM rc = SendMessage(GetHwnd(), LB_GETITEMDATA, n, 0); + if ( rc == LB_ERR && GetLastError() != ERROR_SUCCESS ) + { + wxLogLastError(wxT("LB_GETITEMDATA")); + + return NULL; + } + + return (void *)rc; } void wxListBox::DoSetItemClientData(unsigned int n, void *clientData) -- 2.47.2