Skip to content

Commit

Permalink
core: Sanitize script interface shared pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Jun 25, 2021
1 parent ba0b58d commit 6633e88
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/accumulators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ int auto_update_next_update() {

void auto_update_add(AccumulatorBase *acc) {
assert(acc);
assert(std::find_if(auto_update_accumulators.begin(),
auto_update_accumulators.end(), [acc](auto const &a) {
return a.acc == acc;
}) == auto_update_accumulators.end());
auto_update_accumulators.emplace_back(acc);
}
void auto_update_remove(AccumulatorBase *acc) {
assert(std::find_if(auto_update_accumulators.begin(),
auto_update_accumulators.end(), [acc](auto const &a) {
return a.acc == acc;
}) != auto_update_accumulators.end());
auto_update_accumulators.erase(
boost::remove_if(
auto_update_accumulators,
Expand Down
5 changes: 5 additions & 0 deletions src/core/constraints/Constraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "grid.hpp"
#include "statistics.hpp"

#include <algorithm>
#include <memory>
#include <vector>

Expand Down Expand Up @@ -51,11 +52,15 @@ template <class ParticleRange, class Constraint> class Constraints {
if (not c->fits_in_box(box_geo.length())) {
throw std::runtime_error("Constraint not compatible with box size.");
}
assert(std::find(m_constraints.begin(), m_constraints.end(), c) ==
m_constraints.end());

m_constraints.emplace_back(c);
on_constraint_change();
}
void remove(std::shared_ptr<Constraint> const &c) {
assert(std::find(m_constraints.begin(), m_constraints.end(), c) !=
m_constraints.end());
m_constraints.erase(
std::remove(m_constraints.begin(), m_constraints.end(), c),
m_constraints.end());
Expand Down
4 changes: 4 additions & 0 deletions src/core/grid_based_algorithms/lb_boundaries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ std::vector<std::shared_ptr<LBBoundary>> lbboundaries;
#if defined(LB_BOUNDARIES) || defined(LB_BOUNDARIES_GPU)

void add(const std::shared_ptr<LBBoundary> &b) {
assert(std::find(lbboundaries.begin(), lbboundaries.end(), b) ==
lbboundaries.end());
lbboundaries.emplace_back(b);

on_lbboundary_change();
}

void remove(const std::shared_ptr<LBBoundary> &b) {
assert(std::find(lbboundaries.begin(), lbboundaries.end(), b) !=
lbboundaries.end());
lbboundaries.erase(std::remove(lbboundaries.begin(), lbboundaries.end(), b),
lbboundaries.end());

Expand Down

0 comments on commit 6633e88

Please sign in to comment.