Skip to content

Commit

Permalink
Fix nullpointer issue
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Feb 5, 2024
1 parent b3a99f9 commit 73336c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/openPMD/snapshots/ContainerImpls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class StatefulSnapshotsContainer : public AbstractSnapshotsContainer
auto get() const -> StatefulIterator const *;

public:
using AbstractSnapshotsContainer::currentIteration;
auto currentIteration() -> std::optional<value_type *> override;
auto currentIteration() const -> std::optional<value_type const *> override;

auto begin() -> iterator override;
Expand Down
24 changes: 22 additions & 2 deletions src/snapshots/ContainerImpls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,29 @@ auto StatefulSnapshotsContainer::get() const -> StatefulIterator const *
{
return m_bufferedIterator.value_or(nullptr);
}
auto StatefulSnapshotsContainer::currentIteration()
-> std::optional<value_type *>
{
if (auto it = get(); it)
{
return it->peekCurrentlyOpenIteration();
}
else
{
return nullptr;
}
}
auto StatefulSnapshotsContainer::currentIteration() const
-> std::optional<value_type const *>
{
return get()->peekCurrentlyOpenIteration();
if (auto it = get(); it)
{
return it->peekCurrentlyOpenIteration();
}
else
{
return nullptr;
}
}
auto StatefulSnapshotsContainer::begin() -> iterator
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73336c9

Please sign in to comment.