From b185ffeddcd7d69b0d03d50ab05bc93cee170391 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sun, 20 Oct 2024 08:05:06 +0200 Subject: [PATCH] Check for NULL pointer earlier Reported by Coverity (cherry picked from commit 5ec247a957f446ed0bb26fe958d11aec95c3325c) --- src/frontends/qt/GuiBibtex.cpp | 8 ++++++-- status.24x | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/frontends/qt/GuiBibtex.cpp b/src/frontends/qt/GuiBibtex.cpp index 2c36a91318..70d37b4c7b 100644 --- a/src/frontends/qt/GuiBibtex.cpp +++ b/src/frontends/qt/GuiBibtex.cpp @@ -186,6 +186,8 @@ void GuiBibtex::selUpdated() // check for current file encodings for (int i = 0; i != selected_model_.rowCount(); ++i) { QStandardItem const * key = selected_model_.item(i, 0); + if (!key) + continue; QComboBox * cb = qobject_cast(selectedLV->indexWidget(selected_model_.index(i, 1))); QString fenc = cb ? cb->itemData(cb->currentIndex()).toString() : QString(); if (fenc.isEmpty()) @@ -193,7 +195,7 @@ void GuiBibtex::selUpdated() else cached_file_encodings_[key->text()] = fenc; docstring const enc = qstring_to_ucs4(key->text()) + " " + qstring_to_ucs4(fenc); - if (key && !key->text().isEmpty() && !fenc.isEmpty() && fenc != "general") + if (!key->text().isEmpty() && !fenc.isEmpty() && fenc != "general") nfe.push_back(enc); } } @@ -326,10 +328,12 @@ void GuiBibtex::updateFileEncodings() vector nfe; for (int i = 0; i != selected_model_.rowCount(); ++i) { QStandardItem const * key = selected_model_.item(i, 0); + if (!key) + continue; QComboBox * cb = qobject_cast(selectedLV->indexWidget(selected_model_.index(i, 1))); QString fenc = cb ? cb->itemData(cb->currentIndex()).toString() : QString(); docstring const enc = qstring_to_ucs4(key->text()) + " " + qstring_to_ucs4(fenc); - if (key && !key->text().isEmpty() && !fenc.isEmpty() && fenc != "general") + if (!key->text().isEmpty() && !fenc.isEmpty() && fenc != "general") nfe.push_back(enc); } if (!nfe.empty()) { diff --git a/status.24x b/status.24x index 6211791fdc..8bf34af6f2 100644 --- a/status.24x +++ b/status.24x @@ -84,6 +84,7 @@ What's new * INTERNALS +- Fix some defects found by Coverity. * DOCUMENTATION AND LOCALIZATION