From b8d41208ed3bc4f92e31d0a6a6ac63cdcbdbe28e Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Tue, 8 Feb 2022 12:06:18 +0100 Subject: [PATCH] CBEBouquetWidget: avoid possible crash if no channels available This constellation should be rare, but if no channels are available, bouquet editor will crash here. Verified on generic pc without tuner and Leaksanitizer. For tests it's possible to enable the block with an extra instance of CBouquetManager. So it's still possible to edit bouquets but without channels. Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/7f0f7285e18819caf49a705347955fcf7b7ae690 Author: Thilo Graf Date: 2022-02-08 (Tue, 08 Feb 2022) --- src/gui/bedit/bouqueteditor_bouquets.cpp | 31 ++++++++++++++++++------ 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/gui/bedit/bouqueteditor_bouquets.cpp b/src/gui/bedit/bouqueteditor_bouquets.cpp index 93ae8f835..df21982b2 100644 --- a/src/gui/bedit/bouqueteditor_bouquets.cpp +++ b/src/gui/bedit/bouqueteditor_bouquets.cpp @@ -195,19 +195,36 @@ int CBEBouquetWidget::exec(CMenuTarget* parent, const std::string & /*actionKey* if (parent) parent->hide(); - Bouquets = &g_bouquetManager->Bouquets; - init(); + bool loop = true; - paintHead(); - paintBody(); - paintFoot(); - paintItems(); + // Without check, it would crash if no channels are available (verified on generic pc without tuner) +#if 0 + // for tests, enable this block + static CBouquetManager bm; + g_bouquetManager = &bm; + Bouquets = &g_bouquetManager->Bouquets; +#endif + if (g_bouquetManager) + { + Bouquets = &g_bouquetManager->Bouquets; + + init(); + + paintHead(); + paintBody(); + paintFoot(); + paintItems(); + } + else + { + loop = false; + DisplayErrorMessage("No channels available"); + } bouquetsChanged = false; uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(*timeout_ptr); - bool loop = true; while (loop) { g_RCInput->getMsgAbsoluteTimeout(&msg, &data, &timeoutEnd);