[FarGroup/FarManager] master: Fix crash in debug builds on sending DM_LISTSETCURPOS to an empty menu (ecbce30df)

1 view
Skip to first unread message

farg...@farmanager.com

unread,
May 31, 2024, 8:30:48 AMMay 31
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/ecbce30df9698344b3b5279e2cb95a90b8f872d9

>---------------------------------------------------------------

commit ecbce30df9698344b3b5279e2cb95a90b8f872d9
Author: Shmuel Zeigerman <solo...@gmail.com>
Date: Fri May 31 15:26:20 2024 +0300

Fix crash in debug builds on sending DM_LISTSETCURPOS to an empty menu


>---------------------------------------------------------------

ecbce30df9698344b3b5279e2cb95a90b8f872d9
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 5d647b008..2396e5bee 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 97efd5dbc..de3d83480 100644
--- a/far/vbuild.m4
+++ b/far/vbuild.m4
@@ -1 +1 @@
-6339
+6340
diff --git a/far/vmenu.cpp b/far/vmenu.cpp
index 73094572e..2f99ed76f 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<intptr_t>(Items.size() - 1));
const auto Ret = SetSelectPos(pos, Direct ? Direct : pos > SelectPos? 1 : -1);



Reply all
Reply to author
Forward
0 new messages