]> git.lyx.org Git - features.git/commitdiff
InsetIndex: make a condition more bullet-proof, a nullptr could be dereferenced.
authorThibaut Cuvelier <tcuvelier@lyx.org>
Sun, 8 Jan 2023 21:19:39 +0000 (22:19 +0100)
committerThibaut Cuvelier <tcuvelier@lyx.org>
Sun, 8 Jan 2023 21:19:39 +0000 (22:19 +0100)
Error noticed by Coverity:

*** CID 382777:  Memory - illegal accesses  (RETURN_LOCAL)
/home/lasgoutt/src/lyx/coverity/lyx/src/insets/InsetIndex.cpp: 1866 in _ZNK3lyx15InsetPrintIndex5xhtmlB5cxx11ERNS_9XMLStreamERKNS_12OutputParamsE()
1860
1861            // Collect the index entries in a form we can use them.
1862            vector<IndexEntry> entries;
1863            const docstring & indexType = params().getParamOr("type", from_ascii("idx"));
1864            for (const TocItem& item : *toc) {
1865                    const auto* inset = static_cast<const InsetIndex*>(&(item.dit().inset()));
>>>     CID 382777:  Memory - illegal accesses  (RETURN_LOCAL)
>>>     Using "indexType", which points to an out-of-scope temporary variable of type "lyx::docstring const".
1866                    if (item.isOutput() && inset->params().index == indexType)
1867                            entries.emplace_back(IndexEntry{inset, &op});
1868            }
1869
1870            // If all the index entries are in notes or not displayed, get out sooner.
1871            if (entries.empty())

src/insets/InsetIndex.cpp

index f46001580f68197b7724706de826b08c686808a1..7db133aa61a58f58a97806083f17f1e475495185 100644 (file)
@@ -1858,7 +1858,7 @@ docstring InsetPrintIndex::xhtml(XMLStream &, OutputParams const & op) const
        const docstring & indexType = params().getParamOr("type", from_ascii("idx"));
        for (const TocItem& item : *toc) {
                const auto* inset = static_cast<const InsetIndex*>(&(item.dit().inset()));
-               if (item.isOutput() && inset->params().index == indexType)
+               if (item.isOutput() && inset && inset->params().index == indexType)
                        entries.emplace_back(IndexEntry{inset, &op});
        }