From 7a19622d5ad35702dad2694cca4873693e88bc4e Mon Sep 17 00:00:00 2001 From: Krzysztof Kowalczyk Date: Tue, 7 Jun 2022 17:28:40 -0400 Subject: [PATCH] fix crash if ExternalViewers only has CommandLine (fixes #2691) --- src/Menu.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Menu.cpp b/src/Menu.cpp index 37f849b5947e..268127a15959 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -1156,18 +1156,15 @@ static void AppendExternalViewersToMenu(HMENU menuFile, const WCHAR* filePath) { } WCHAR* name = ToWstrTemp(ev->name); - if (str::EmptyOrWhiteSpaceOnly(ev->name)) { + if (!ev->name || str::EmptyOrWhiteSpaceOnly(ev->name)) { CmdLineArgsIter args(ToWstrTemp(ev->commandLine)); - int nArgs = args.nArgs - 2; - if (nArgs <= 0) { + int nArgs = args.nArgs; + if (nArgs < 1) { continue; } - WCHAR* arg0 = args.at(2 + 0); - name = str::DupTemp(path::GetBaseNameTemp(arg0)); - WCHAR* ext = (WCHAR*)path::GetExtTemp(name); - if (ext) { - *ext = 0; - } + WCHAR* exePath = args.at(0); + const WCHAR* exeName = path::GetBaseNameTemp(exePath); + name = str::DupTemp(exeName); } AutoFreeWstr menuString(str::Format(_TR("Open in %s"), name));