### Bug Summary

File: | builds/wireshark/wireshark/ui/qt/welcome_page.cpp
Warning: | line 324, column 10 Value stored to 'collapseLinks' during its initialization is never read

### Annotated Source Code

Press '?' to see keyboard shortcuts

Show analyzer invocation
clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name welcome_page.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-22/lib/clang/22 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /builds/wireshark/wireshark/build/ui/qt -isystem /builds/wireshark/wireshark/ui/qt -isystem /builds/wireshark/wireshark/ui/qt/lua_debugger -isystem /usr/include/x86_64-linux-gnu/qt6/QtConcurrent -isystem /usr/include/x86_64-linux-gnu/qt6 -isystem /usr/include/x86_64-linux-gnu/qt6/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt6/mkspecs/linux-g++ -isystem /usr/include/x86_64-linux-gnu/qt6/QtNetwork -isystem /usr/include/x86_64-linux-gnu/qt6/QtPrintSupport -isystem /usr/include/x86_64-linux-gnu/qt6/QtGui -isystem /usr/include/x86_64-linux-gnu/qt6/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt6/QtSvg -isystem /usr/include/x86_64-linux-gnu/qt6/QtMultimedia -isystem /usr/include/x86_64-linux-gnu/qt6/QtDBus -D CARES_NO_DEPRECATED -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D QT_CONCURRENT_LIB -D QT_CORE_LIB -D QT_DBUS_LIB -D QT_GUI_LIB -D QT_MULTIMEDIA_LIB -D QT_NETWORK_LIB -D QT_PRINTSUPPORT_LIB -D QT_SVG_LIB -D QT_WIDGETS_LIB -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build/ui/qt/qtui_autogen/include -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-22/lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-nonliteral -std=c++17 -fdeprecated-macro -ferror-limit 19 -fwrapv -fwrapv-pointer -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /builds/wireshark/wireshark/sbout/2026-08-01-100307-3660-1 -x c++ /builds/wireshark/wireshark/ui/qt/welcome_page.cpp

Keyboard shortcuts:

- Use 'j/k' keys for keyboard navigation
- Use 'Shift+S' to show/hide relevant lines
- Use '?' to toggle this window

Close
Show only relevant lines Show control flow arrows

1 | /* welcome_page.cpp
2 | *
3 | * Wireshark - Network traffic analyzer
4 | * By Gerald Combs <gerald@wireshark.org>
5 | * Copyright 1998 Gerald Combs
6 | *
7 | * SPDX-License-Identifier: GPL-2.0-or-later
8 | */
9 |
10 | #include "config.h"
11 |
12 | #include <epan/prefs.h>
13 |
14 | #include "ui/recent.h"
15 | #include "ui/urls.h"
16 |
17 | #include <app/application_flavor.h>
18 |
19 | #include "welcome_page.h"
20 | #include <ui_welcome_page.h>
21 | #include <ui/qt/utils/qt_ui_utils.h>
22 | #include <ui/qt/utils/theme_manager.h>
23 | #include <ui/qt/models/recentcapturefiles_list_model.h>
24 | #include <ui/qt/utils/workspace_state.h>
25 | #include <ui/qt/widgets/capture_card_widget.h>
26 |
27 | #include "main_application.h"
28 |
29 | #include <QClipboard>
30 | #include <QDesktopServices>
31 | #include <QDir>
32 | #include <QListWidget>
33 | #include <QMenu>
34 | #include <QResizeEvent>
35 | #include <QUrl>
36 | #include <QWidget>
37 |
38 | #ifndef VERSION_FLAVOR"Development Build"
39 | #define VERSION_FLAVOR"Development Build" ""
40 | #endif
41 |
42 | WelcomePage::WelcomePage(QWidget *parent) :
43 | QFrame(parent),
44 | welcome_ui_(new Ui::WelcomePage),
45 | #ifdef Q_OS_MAC
46 | show_in_str_(tr("Show in Finder")),
47 | #else
48 | show_in_str_(tr("Show in Folder")),
49 | #endif
50 | splash_overlay_(NULL__null)
51 |
52 | {
53 | welcome_ui_->setupUi(this);
54 |
55 | setContentsMargins(0, 0, 0, 0);
56 | setAccessibleName(tr("Welcome page"));
57 | setAccessibleDescription(tr("The %1 welcome page provides access to recent files, capture interfaces, and learning resources.").arg(mainApp->applicationName()));
58 |
59 | /* Initially set the sidebar hidden, it will be made visible or not by
60 | * applySidebarPreferences. */
61 | welcome_ui_->sidebarContainer->setVisible(false);
62 |
63 | updateStyleSheets();
64 |
65 | /* Handle Recent Capture Files List */
66 | // In welcome_page.cpp or wherever the list is created
67 | auto *model = new RecentCaptureFilesListModel(this);
68 | auto *proxyModel = new RecentCaptureFilesReverseProxyModel(this);
69 | proxyModel->setSourceModel(model);
70 |
71 | welcome_ui_->openFileSectionRecentList->setVisible(true);
72 | welcome_ui_->openFileSectionRecentList->setModel(proxyModel);
73 | welcome_ui_->openFileSectionRecentList->setItemDelegate(new RecentCaptureFilesDelegate(welcome_ui_->openFileSectionRecentList));
74 | welcome_ui_->openFileSectionRecentList->setContextMenuPolicy(Qt::CustomContextMenu);
75 | welcome_ui_->openFileSectionRecentList->setAccessibleName(tr("Recent capture files"));
76 | welcome_ui_->openFileSectionRecentList->setAccessibleDescription(tr("List of recently opened capture files. Double-click or press Enter to open."));
77 | connect(welcome_ui_->openFileSectionRecentList, &QListView::activated,
78 | this, [this]() {
79 | QModelIndex index = welcome_ui_->openFileSectionRecentList->currentIndex();
80 | if (index.isValid()) {
81 | QString cfile = index.data(RecentCaptureFilesListModel::FilenameRole).toString();
82 | emit recentFileActivated(cfile);
83 | }
84 | });
85 | connect(welcome_ui_->openFileSectionRecentList, &QListView::customContextMenuRequested,
86 | this, &WelcomePage::showCaptureFilesContextMenu);
87 |
88 | if (WorkspaceState::instance()->recentCaptureFiles().size() > 0) {
89 | welcome_ui_->openFileSectionLabel->setVisible(true);
90 | welcome_ui_->openFileSectionRecentList->setVisible(true);
91 | } else {
92 | welcome_ui_->openFileSectionLabel->setVisible(false);
93 | welcome_ui_->openFileSectionRecentList->setVisible(false);
94 | }
95 |
96 | #ifdef Q_OS_MAC
97 | welcome_ui_->openFileSectionRecentList->setAttribute(Qt::WA_MacShowFocusRect, false);
98 | #endif
99 |
100 | welcome_ui_->openFileSectionRecentList->setTextElideMode(Qt::ElideLeft);
101 |
102 | mainApp->whenInitialized(this, [this]() { appInitialized(); });
103 | connect(mainApp, &MainApplication::preferencesChanged, this, &WelcomePage::applySidebarPreferences);
104 |
105 | // "Capture" header click opens Capture Options dialog
106 | if (auto *captureHeader = welcome_ui_->captureSectionCard->findChild<ClickableLabel*>(QStringLiteral("captureHeader")(QString(QtPrivate::qMakeStringPrivate(u"" "captureHeader"))))) {
107 | connect(captureHeader, &ClickableLabel::clicked, this, []() {
108 | mainApp->doTriggerMenuItem(MainApplication::CaptureOptionsDialog);
109 | });
110 | }
111 |
112 | splash_overlay_ = new SplashOverlay(this);
113 | }
114 |
115 | WelcomePage::~WelcomePage()
116 | {
117 | delete welcome_ui_;
118 | }
119 |
120 | InterfaceFrame *WelcomePage::getInterfaceFrame()
121 | {
122 | return welcome_ui_->captureSectionCard->interfaceFrame();
123 | }
124 |
125 | CaptureCardWidget *WelcomePage::captureCard()
126 | {
127 | return welcome_ui_->captureSectionCard;
128 | }
129 |
130 | const QString WelcomePage::captureFilter()
131 | {
132 | return welcome_ui_->captureSectionCard->captureFilter();
133 | }
134 |
135 | void WelcomePage::setCaptureFilter(const QString capture_filter)
136 | {
137 | welcome_ui_->captureSectionCard->setCaptureFilter(capture_filter);
138 | }
139 |
140 | void WelcomePage::setCaptureFilterText(const QString capture_filter)
141 | {
142 | welcome_ui_->captureSectionCard->setCaptureFilterText(capture_filter);
143 | }
144 |
145 | void WelcomePage::interfaceSelected()
146 | {
147 | welcome_ui_->captureSectionCard->interfaceSelected();
148 | }
149 |
150 | void WelcomePage::appInitialized()
151 | {
152 | applySidebarPreferences();
153 |
154 | splash_overlay_->fadeOut();
155 | splash_overlay_ = NULL__null;
156 |
157 | // Ensure sidebar layout adapts to the restored window size.
158 | // resizeEvent may have fired before the layout was finalized.
159 | updateSidebarLayout();
160 | }
161 |
162 | void WelcomePage::applySidebarPreferences()
163 | {
164 | // There are slides that will be shown EVEN if the section card is set hidden through the preferences.
165 | // hasVisibleSlides() checks if there are any slides that should be shown, as well as the user's preferences.
166 | bool slidesAreVisible = welcome_ui_->tipsSectionCard->hasVisibleSlides();
167 |
168 | welcome_ui_->tipsSectionCard->setSlideDeckFreeze(true);
169 | welcome_ui_->tipsSectionCard->setSlideTypeVisible(BannerEvents, recent.gui_welcome_page_sidebar_tips_events);
170 | welcome_ui_->tipsSectionCard->setSlideTypeVisible(BannerSponsorship, recent.gui_welcome_page_sidebar_tips_sponsorship);
171 | welcome_ui_->tipsSectionCard->setSlideTypeVisible(BannerTips, recent.gui_welcome_page_sidebar_tips_tips);
172 | welcome_ui_->tipsSectionCard->setSlidesTest(recent.gui_welcome_page_sidebar_tips_slides_test);
173 | welcome_ui_->tipsSectionCard->setSlideDeckFreeze(false);
174 | welcome_ui_->tipsSectionCard->setAutoAdvance(recent.gui_welcome_page_sidebar_tips_auto_advance);
175 | welcome_ui_->tipsSectionCard->setAutoAdvanceInterval(recent.gui_welcome_page_sidebar_tips_interval);
176 | welcome_ui_->tipsSectionCard->setVisible(slidesAreVisible);
177 |
178 | welcome_ui_->learnSectionCard->setVisible(recent.gui_welcome_page_sidebar_learn_visible);
179 |
180 | // Hide the entire sidebar container when all sidebar widgets are disabled,
181 | // so the main content area can expand to fill the full window width.
182 | bool sidebar_visible = slidesAreVisible || recent.gui_welcome_page_sidebar_learn_visible;
183 | welcome_ui_->sidebarContainer->setVisible(sidebar_visible);
184 |
185 | // Ensure sidebar layout adapts to the restored window size.
186 | // (XXX - This really only needs to happen if one of the cards is switching
187 | // to visible, and only if this is the first time being shown or if a
188 | // ResizeEvent occurred while hidden. But preference changes should be
189 | // rare.)
190 | updateSidebarLayout();
191 | }
192 |
193 | bool WelcomePage::event(QEvent *event)
194 | {
195 | switch (event->type()) {
196 | case QEvent::ApplicationPaletteChange:
197 | {
198 | updateStyleSheets();
199 | break;
200 | }
201 | case QEvent::LanguageChange:
202 | {
203 | welcome_ui_->retranslateUi(this);
204 | break;
205 | }
206 | default:
207 | break;
208 |
209 | }
210 | return QFrame::event(event);
211 | }
212 |
213 | void WelcomePage::resizeEvent(QResizeEvent *event)
214 | {
215 | if (splash_overlay_)
216 | splash_overlay_->resize(event->size());
217 |
218 | QFrame::resizeEvent(event);
219 |
220 | updateSidebarLayout();
221 | }
222 |
223 | void WelcomePage::showEvent(QShowEvent *event)
224 | {
225 | QFrame::showEvent(event);
226 |
227 | // The final window geometry may not be known until the widget is shown
228 | // (especially on macOS with restored window positions). Ensure the
229 | // sidebar layout adapts to the actual available space.
230 | updateSidebarLayout();
231 | }
232 |
233 | /*
234 | * Adapts the sidebar widget states to the available vertical space.
235 | *
236 | * The sidebar contains two widgets stacked vertically with spacing between
237 | * them: the InfoBannerWidget (tips/sponsors) and the LearnCardWidget (docs
238 | * links + action buttons). Both support a compact mode to reduce their
239 | * height when the window is small.
240 | *
241 | * Collapse order (as the window shrinks):
242 | * 1. LearnCardWidget links collapse (vertical list -> horizontal row)
243 | * 2. InfoBannerWidget compacts (hides illustration and body text)
244 | *
245 | * Expand order (as the window grows) is the reverse:
246 | * 1. InfoBannerWidget expands back to full
247 | * 2. LearnCardWidget links expand back to vertical
248 | *
249 | * All size values are queried from the widgets and layout, not hardcoded:
250 | * - tipsFull: InfoBannerWidget::sizeHint().height()
251 | * Always returns the full preferred height (360) regardless
252 | * of compact state. This is stable because sizeHint()
253 | * reports what the widget *wants*, while compact mode is
254 | * enforced via setMaximumHeight().
255 | * - learnMax: LearnCardWidget::maximumHeight() (from .ui: 240)
256 | * - learnMin: LearnCardWidget::minimumHeight() (from .ui: 110)
257 | * - spacing: sidebarLayout->spacing() (from .ui: 16)
258 | *
259 | * Hysteresis (kHysteresis = 20px):
260 | * Without hysteresis, at the exact collapse threshold the layout
261 | * oscillates: collapsing a widget frees space, which satisfies the
262 | * expand threshold, which expands, which exceeds the threshold again.
263 | * On each resize event this cycle repeats, causing visible flickering.
264 | *
265 | * Hysteresis adds a dead zone between collapse and expand thresholds.
266 | * A widget collapses at threshold T but only re-expands at T + 20.
267 | * In the 20px gap, the current state is preserved.
268 | *
269 | * The value 20px was chosen empirically: it must be large enough that
270 | * the layout geometry change from collapsing/expanding a widget (which
271 | * can shift available height by a few pixels due to rounding, spacing,
272 | * and platform differences) doesn't cross back over the threshold. In
273 | * practice, resize events during a user drag arrive ~8-12px apart, so
274 | * 20px ensures at least one stable frame at the boundary. A larger
275 | * value would delay the transition visibly; a smaller one risks not
276 | * fully suppressing the oscillation on high-DPI displays where pixel
277 | * increments are coarser.
278 | *
279 | * Decision zones (with current widget sizes):
280 | *
281 | * available >= 636 (linksExpandAt)
282 | * -> full tips + expanded links
283 | *
284 | * available >= 506 (tipsExpandAt) and < 636
285 | * -> full tips + collapsed links
286 | * (between 616-635: hysteresis zone for links -- keeps current state
287 | * if already expanded, won't re-expand if collapsed)
288 | *
289 | * available >= 486 (tipsCompactAt) and < 506
290 | * -> hysteresis zone for tips -- keeps current tips state,
291 | * links forced collapsed
292 | *
293 | * available < 486 (tipsCompactAt)
294 | * -> compact tips + collapsed links
295 | *
296 | * Called from: resizeEvent(), showEvent(), appInitialized(), and
297 | * indirectly via updateGeometry() when the welcome header banner
298 | * visibility changes.
299 | */
300 | void WelcomePage::updateSidebarLayout()
301 | {
302 | int available = welcome_ui_->sidebarContainer->height();
303 | if (available <= 0)
304 | return;
305 |
306 | static const int kHysteresis = 20;
307 |
308 | int spacing = welcome_ui_->sidebarLayout->spacing();
309 | int tipsFull = welcome_ui_->tipsSectionCard->sizeHint().height();
310 | int learnMax = welcome_ui_->learnSectionCard->maximumHeight();
311 | int learnMin = welcome_ui_->learnSectionCard->minimumHeight();
312 |
313 | // Collapse threshold: the minimum available height to show this state.
314 | // Expand threshold: collapse + hysteresis -- prevents oscillation.
315 |
316 | // Level 1: links collapse when full tips + expanded learn don't fit.
317 | int linksCollapseAt = tipsFull + spacing + learnMax;
318 | int linksExpandAt = linksCollapseAt + kHysteresis;
319 |
320 | // Level 2: tips compact when full tips + collapsed learn don't fit.
321 | int tipsCompactAt = tipsFull + spacing + learnMin;
322 | int tipsExpandAt = tipsCompactAt + kHysteresis;
323 |
324 | bool collapseLinks = welcome_ui_->learnSectionCard->isLinksCollapsed();
| Value stored to 'collapseLinks' during its initialization is never read
325 | bool compactTips = welcome_ui_->tipsSectionCard->isCompactMode();
326 |
327 | if (available >= linksExpandAt) {
328 | collapseLinks = false;
329 | compactTips = false;
330 | } else if (available >= tipsExpandAt) {
331 | collapseLinks = true;
332 | compactTips = false;
333 | } else if (available >= tipsCompactAt) {
334 | collapseLinks = true;
335 | // tips state preserved (hysteresis zone)
336 | } else {
337 | collapseLinks = true;
338 | compactTips = true;
339 | }
340 |
341 | welcome_ui_->learnSectionCard->setLinksCollapsed(collapseLinks);
342 | welcome_ui_->tipsSectionCard->setCompactMode(compactTips);
343 | }
344 |
345 | void WelcomePage::showCaptureFilesContextMenu(QPoint pos)
346 | {
347 | QModelIndex index = welcome_ui_->openFileSectionRecentList->indexAt(pos);
348 | if (!index.isValid()) return;
349 |
350 | QMenu *recent_ctx_menu = new QMenu(this);
351 | recent_ctx_menu->setAttribute(Qt::WA_DeleteOnClose);
352 |
353 | QModelIndex sourceIndex = static_cast<QSortFilterProxyModel*>(welcome_ui_->openFileSectionRecentList->model())->mapToSource(index);
354 | RecentCaptureFilesListModel *model = static_cast<RecentCaptureFilesListModel*>(
355 | static_cast<QSortFilterProxyModel*>(welcome_ui_->openFileSectionRecentList->model())->sourceModel());
356 |
357 | QString filePath = model->data(sourceIndex, RecentCaptureFilesListModel::FilenameRole).toString();
358 | bool accessible = model->data(sourceIndex, RecentCaptureFilesListModel::AccessibleRole).toBool();
359 |
360 | QAction *show_action = recent_ctx_menu->addAction(show_in_str_);
361 | show_action->setEnabled(accessible);
362 | connect(show_action, &QAction::triggered, this, [filePath]{ desktop_show_in_folder(filePath); });
363 |
364 | QAction *copy_action = recent_ctx_menu->addAction(tr("Copy file path"));
365 | connect(copy_action, &QAction::triggered, this, [filePath]{ mainApp->clipboard()->setText(filePath); });
366 |
367 | recent_ctx_menu->addSeparator();
368 |
369 | QAction *remove_action = recent_ctx_menu->addAction(tr("Remove from list"));
370 | connect(remove_action, &QAction::triggered, this, [filePath]{
371 | WorkspaceState::instance()->removeRecentCaptureFile(filePath);
372 | });
373 |
374 | recent_ctx_menu->popup(welcome_ui_->openFileSectionRecentList->viewport()->mapToGlobal(pos));
375 | }
376 |
377 | void WelcomePage::updateStyleSheets()
378 | {
379 | setStyleSheet(ThemeManager::styleSheet(QStringLiteral("welcome-page")(QString(QtPrivate::qMakeStringPrivate(u"" "welcome-page")))));
380 |
381 | /* LearnCardWidget and CaptureCardWidget manage their own stylesheets */
382 | }
383 |
384 | void WelcomePage::on_openFileSectionLabel_clicked()
385 | {
386 | mainApp->doTriggerMenuItem(MainApplication::FileOpenDialog);
387 | }