From 73336c9f9a16c681d64703b2a5d70963fbc4ecb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Wed, 31 Jan 2024 15:09:25 +0100 Subject: [PATCH] Fix nullpointer issue --- include/openPMD/snapshots/ContainerImpls.hpp | 2 +- src/snapshots/ContainerImpls.cpp | 24 ++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/openPMD/snapshots/ContainerImpls.hpp b/include/openPMD/snapshots/ContainerImpls.hpp index adc14c1be7..510fe1b768 100644 --- a/include/openPMD/snapshots/ContainerImpls.hpp +++ b/include/openPMD/snapshots/ContainerImpls.hpp @@ -20,7 +20,7 @@ class StatefulSnapshotsContainer : public AbstractSnapshotsContainer auto get() const -> StatefulIterator const *; public: - using AbstractSnapshotsContainer::currentIteration; + auto currentIteration() -> std::optional override; auto currentIteration() const -> std::optional override; auto begin() -> iterator override; diff --git a/src/snapshots/ContainerImpls.cpp b/src/snapshots/ContainerImpls.cpp index 11524d5eec..5719d125d1 100644 --- a/src/snapshots/ContainerImpls.cpp +++ b/src/snapshots/ContainerImpls.cpp @@ -39,10 +39,29 @@ auto StatefulSnapshotsContainer::get() const -> StatefulIterator const * { return m_bufferedIterator.value_or(nullptr); } +auto StatefulSnapshotsContainer::currentIteration() + -> std::optional +{ + if (auto it = get(); it) + { + return it->peekCurrentlyOpenIteration(); + } + else + { + return nullptr; + } +} auto StatefulSnapshotsContainer::currentIteration() const -> std::optional { - return get()->peekCurrentlyOpenIteration(); + if (auto it = get(); it) + { + return it->peekCurrentlyOpenIteration(); + } + else + { + return nullptr; + } } auto StatefulSnapshotsContainer::begin() -> iterator { @@ -93,7 +112,8 @@ auto StatefulSnapshotsContainer::rend() const -> const_iterator bool StatefulSnapshotsContainer::empty() const { - return get()->operator bool(); + auto it = get(); + return (!it) || it->operator bool(); } auto StatefulSnapshotsContainer::at(key_type const &) const