From ecbce30df9698344b3b5279e2cb95a90b8f872d9 Mon Sep 17 00:00:00 2001 From: Shmuel Zeigerman Date: Fri, 31 May 2024 15:26:20 +0300 Subject: [PATCH] Fix crash in debug builds on sending DM_LISTSETCURPOS to an empty menu --- far/changelog | 5 +++++ far/vbuild.m4 | 2 +- far/vmenu.cpp | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/far/changelog b/far/changelog index 5d647b0088..2396e5beea 100644 --- a/far/changelog +++ b/far/changelog @@ -1,3 +1,8 @@ +-------------------------------------------------------------------------------- +shmuel 2024-05-31 15:20:31+03:00 - build 6340 + +1. Fix crash in debug builds on sending DM_LISTSETCURPOS to an empty menu. + -------------------------------------------------------------------------------- shmuel 2024-05-31 00:00:44+03:00 - build 6339 diff --git a/far/vbuild.m4 b/far/vbuild.m4 index 97efd5dbc5..de3d834804 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -6339 +6340 diff --git a/far/vmenu.cpp b/far/vmenu.cpp index 73094572e6..2f99ed76f4 100644 --- a/far/vmenu.cpp +++ b/far/vmenu.cpp @@ -612,6 +612,9 @@ int VMenu::SetSelectPos(int Pos, int Direct, bool stop_on_edge) // установить курсор и верхний элемент int VMenu::SetSelectPos(const FarListPos *ListPos, int Direct) { + if (Items.empty()) + return -1; + const auto pos = std::clamp(ListPos->SelectPos, intptr_t{}, static_cast(Items.size() - 1)); const auto Ret = SetSelectPos(pos, Direct ? Direct : pos > SelectPos? 1 : -1);