Skip to content

Commit

Permalink
Fix nullpointer issue
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Jan 31, 2024
1 parent 67842ca commit 0ee77a2
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 0ee77a2

Please sign in to comment.