Opened 10 months ago

Closed 10 months ago

Last modified 9 months ago

#15578 closed defect (fixed)

wxListEvent::GetData() broken in 64bit builds

Reported by: dconnet Owned by:
Priority: normal Milestone: 3.0.0
Component: GUI-all Version: stable-latest
Keywords: Cc:
Blocked By: Blocking:
Patch: yes


Using trunk (r74990), compile artprov sample (I'm on windows, x64, static build). Click menu File->ResourcesBrowser.

Click on any entry in list, crash.


Index: samples/artprov/artbrows.cpp
--- samples/artprov/artbrows.cpp        (revision 74990)
+++ samples/artprov/artbrows.cpp        (working copy)
@@ -197,7 +197,7 @@

 void wxArtBrowserDialog::OnSelectItem(wxListEvent &event)
-    const char *data = (const char*)event.GetData();
+    const char *data = (const char*)m_list->GetItemData(event.GetIndex());
     SetArtBitmap(data, m_client, wxDefaultSize);

Change History (6)

comment:1 Changed 10 months ago by vadz

Very strange, I don't see this in 32 bit build, so it would seem that there is a pointer truncation somewhere in 64 bits.

Could you please check what is the value of the data associated with the event?

comment:2 Changed 10 months ago by dconnet

It has an address, but (copied from 'Autos' window):

+		data	0x000000003faaafc0 <Error reading characters of string.>	const char *

It sounds like pointer truncation is happening - like what used to happen in the user data section of listctrl sorting.

Uhoh. Looks like the problem is in listbase.h - it's not designed to work with pointers:

long GetData() const { return static_cast<long>(m_item.m_data); }

comment:3 Changed 10 months ago by vadz

  • Component changed from samples to GUI-all
  • Milestone set to 3.0
  • Summary changed from artprov sample crashes to wxListEvent::GetData() broken in 64bit builds

Could you please check if the following is enough to fix it?

  • include/wx/listbase.h

    diff --git a/include/wx/listbase.h b/include/wx/listbase.h
    index 80f65f2..5e6fb7c 100644
    a b class WXDLLIMPEXP_CORE wxListEvent : public wxNotifyEvent 
    510510    const wxString& GetLabel() const { return m_item.m_text; } 
    511511    const wxString& GetText() const { return m_item.m_text; } 
    512512    int GetImage() const { return m_item.m_image; } 
    513     long GetData() const { return static_cast<long>(m_item.m_data); } 
     513    wxUIntPtr GetData() const { return m_item.m_data; } 
    514514    long GetMask() const { return m_item.m_mask; } 
    515515    const wxListItem& GetItem() const { return m_item; } 


comment:4 Changed 10 months ago by dconnet

Confirmed. Fix is good.

comment:5 Changed 10 months ago by VZ

  • Resolution set to fixed
  • Status changed from new to closed

(In [75005]) Fix pointer truncation in wxListEvent::GetData() in LLP64 builds.

We must use wxUIntPtr and not long here to avoid truncating the upper half of
the pointer when sizeof(void*)>sizeof(long).

Closes #15578.

comment:6 Changed 9 months ago by VZ

(In [75135]) Update wxListEvent::GetData() documentation too.

It returns wxUIntPtr and not long since r75000, see #15578.

Note: See TracTickets for help on using tickets.