diff --git a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch index d62ea92e..b5ffac76 100644 --- a/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch +++ b/thirdparty/wx-rs/patches/0003-widget-bridge-cpp.patch @@ -1,6 +1,6 @@ --- a/cpp_src/widgets_bridge.cpp +++ b/cpp_src/widgets_bridge.cpp -@@ -0,0 +1,1059 @@ +@@ -0,0 +1,1064 @@ +// widgets_bridge.cpp — alkane-toolkit extension to wx-rs +// Adds the widget/event surface the toolkit UI needs on top of the upstream +// render-callback bridge (which is kept untouched). @@ -701,9 +701,11 @@ +} + +// Scroll so `row` is visible (used with wxbr_dvlc_get_top_row to restore the -+// scroll position after a refill). Out-of-range rows are ignored. ++// scroll position after a refill). Out-of-range rows are ignored -- GetItem() ++// itself asserts on row >= count, so the bound MUST be checked before calling. +void wxbr_dvlc_ensure_visible(void* win, unsigned row) { + wxDataViewCtrl* dv = (wxDataViewCtrl*)win; ++ if (row >= (unsigned)dvlc_store(win)->GetItemCount()) return; + wxDataViewItem item = ((wxDataViewIndexListModel*)dv->GetModel())->GetItem(row); + if (item.IsOk()) dv->EnsureVisible(item); +} @@ -806,9 +808,11 @@ +void wxbr_dvlc_select_rows(void* win, const int* rows, int n) { + wxDataViewCtrl* dv = (wxDataViewCtrl*)win; + wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel(); ++ int count = (int)dvlc_store(win)->GetItemCount(); + dv->UnselectAll(); + for (int i = 0; i < n; i++) { -+ if (rows[i] >= 0) dv->Select(m->GetItem((unsigned)rows[i])); ++ // GetItem() asserts on an out-of-range row, so bound both ends. ++ if (rows[i] >= 0 && rows[i] < count) dv->Select(m->GetItem((unsigned)rows[i])); + } +} + @@ -827,6 +831,7 @@ + if (row < 0) return; + wxDataViewCtrl* dv = (wxDataViewCtrl*)win; + wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel(); ++ if (row >= (long)dvlc_store(win)->GetItemCount()) return; + dv->Select(m->GetItem((unsigned)row)); +} + diff --git a/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp b/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp index 4f11c301..8fdbd578 100644 --- a/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp +++ b/thirdparty/wx-rs/wx-rs-0.2.0-patched/cpp_src/widgets_bridge.cpp @@ -698,9 +698,11 @@ int wxbr_dvlc_get_top_row(void* win) { } // Scroll so `row` is visible (used with wxbr_dvlc_get_top_row to restore the -// scroll position after a refill). Out-of-range rows are ignored. +// scroll position after a refill). Out-of-range rows are ignored -- GetItem() +// itself asserts on row >= count, so the bound MUST be checked before calling. void wxbr_dvlc_ensure_visible(void* win, unsigned row) { wxDataViewCtrl* dv = (wxDataViewCtrl*)win; + if (row >= (unsigned)dvlc_store(win)->GetItemCount()) return; wxDataViewItem item = ((wxDataViewIndexListModel*)dv->GetModel())->GetItem(row); if (item.IsOk()) dv->EnsureVisible(item); } @@ -803,9 +805,11 @@ int wxbr_dvlc_get_selections(void* win, int* buf, int cap) { void wxbr_dvlc_select_rows(void* win, const int* rows, int n) { wxDataViewCtrl* dv = (wxDataViewCtrl*)win; wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel(); + int count = (int)dvlc_store(win)->GetItemCount(); dv->UnselectAll(); for (int i = 0; i < n; i++) { - if (rows[i] >= 0) dv->Select(m->GetItem((unsigned)rows[i])); + // GetItem() asserts on an out-of-range row, so bound both ends. + if (rows[i] >= 0 && rows[i] < count) dv->Select(m->GetItem((unsigned)rows[i])); } } @@ -824,6 +828,7 @@ void wxbr_dvlc_select_row(void* win, long row) { if (row < 0) return; wxDataViewCtrl* dv = (wxDataViewCtrl*)win; wxDataViewIndexListModel* m = (wxDataViewIndexListModel*)dv->GetModel(); + if (row >= (long)dvlc_store(win)->GetItemCount()) return; dv->Select(m->GetItem((unsigned)row)); }