From 77204bf119fdfc557f330d24cbc260f68609a8b1 Mon Sep 17 00:00:00 2001 From: Thorsten Hater <24411438+thorstenhater@users.noreply.github.com> Date: Fri, 16 Sep 2022 16:13:03 +0200 Subject: [PATCH] Fix some issues found by PVS Studio. (#1974) --- arbor/cable_cell_param.cpp | 2 +- arbor/include/arbor/event_generator.hpp | 3 ++- arbor/include/arbor/schedule.hpp | 8 +++++--- arbor/mechcat.cpp | 2 +- arbor/morph/segment_tree.cpp | 4 ++-- arbor/util/ordered_forest.hpp | 4 ++-- cmake/FindPythonModule.cmake | 1 - python/schedule.hpp | 2 +- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/arbor/cable_cell_param.cpp b/arbor/cable_cell_param.cpp index e272781b..79d6b670 100644 --- a/arbor/cable_cell_param.cpp +++ b/arbor/cable_cell_param.cpp @@ -98,7 +98,7 @@ std::vector<defaultable> cable_cell_parameter_set::serialize() const { if (data.init_reversal_potential) { D.push_back(init_reversal_potential{name, *data.init_reversal_potential}); } - if (data.init_reversal_potential) { + if (data.diffusivity) { D.push_back(ion_diffusivity{name, *data.diffusivity}); } } diff --git a/arbor/include/arbor/event_generator.hpp b/arbor/include/arbor/event_generator.hpp index 5e14ecb4..c378ef7d 100644 --- a/arbor/include/arbor/event_generator.hpp +++ b/arbor/include/arbor/event_generator.hpp @@ -12,6 +12,7 @@ #include <arbor/generic_event.hpp> #include <arbor/spike_event.hpp> #include <arbor/schedule.hpp> +#include <arbor/arbexcept.hpp> namespace arb { @@ -73,7 +74,7 @@ struct event_generator { } event_seq events(time_type t0, time_type t1) { - if (!resolved_) throw ; + if (!resolved_) throw arbor_internal_error("Unresolved label in event generator."); auto tgt = *resolved_; auto ts = sched_.events(t0, t1); diff --git a/arbor/include/arbor/schedule.hpp b/arbor/include/arbor/schedule.hpp index 253efa7b..2f3562f7 100644 --- a/arbor/include/arbor/schedule.hpp +++ b/arbor/include/arbor/schedule.hpp @@ -65,7 +65,9 @@ private: virtual ~interface() {} }; - std::unique_ptr<interface> impl_; + using iface_ptr = std::unique_ptr<interface> ; + + iface_ptr impl_; template <typename Impl> struct wrap: interface { @@ -80,8 +82,8 @@ private: wrapped.reset(); } - virtual std::unique_ptr<interface> clone() { - return std::unique_ptr<interface>(new wrap<Impl>(wrapped)); + virtual iface_ptr clone() { + return std::make_unique<wrap<Impl>>(wrapped); } Impl wrapped; diff --git a/arbor/mechcat.cpp b/arbor/mechcat.cpp index 06c60ed2..58dfd902 100644 --- a/arbor/mechcat.cpp +++ b/arbor/mechcat.cpp @@ -620,7 +620,7 @@ ARB_ARBOR_API const mechanism_catalogue load_catalogue(const std::string& fn) { for(int ix = 0; ix < count; ++ix) { auto type = mechs[ix].type(); auto name = std::string{type.name}; - if (name == "") { + if (name.empty()) { throw bad_catalogue_error{util::pprintf("Empty name for mechanism in '{}'", fn)}; } auto icpu = mechs[ix].i_cpu(); diff --git a/arbor/morph/segment_tree.cpp b/arbor/morph/segment_tree.cpp index 3a10a015..43c353b5 100644 --- a/arbor/morph/segment_tree.cpp +++ b/arbor/morph/segment_tree.cpp @@ -19,7 +19,7 @@ struct node_t { using node_p = std::function<bool(const node_t&)>; -node_p yes = [](const node_t&) { return true; }; +node_p yes = [](node_t) { return true; }; // invert parent <*> child relation, returns a map of parent_id -> [children_id] // For predictable ordering we sort the vectors. @@ -40,7 +40,7 @@ std::map<msize_t, std::vector<msize_t>> tree_to_children(const segment_tree& tre // - init: initial tree to append to // Note: this is basically a recursive function w/ an explicit stack. segment_tree copy_if(const segment_tree& tree, - const node_t& start, + node_t start, node_p predicate, const segment_tree& init={}) { auto children_of = tree_to_children(tree); diff --git a/arbor/util/ordered_forest.hpp b/arbor/util/ordered_forest.hpp index 38a8bc09..a1346af6 100644 --- a/arbor/util/ordered_forest.hpp +++ b/arbor/util/ordered_forest.hpp @@ -420,7 +420,7 @@ public: { sibling_iterator j; for (auto& b: blist) { - ordered_forest f(std::move(b.f_), item_alloc_); + ordered_forest f(b.f_, item_alloc_); j = j? graft_after(j, std::move(f)): sibling_iterator(graft_front(std::move(f))); } } @@ -652,7 +652,7 @@ struct ordered_forest_builder { sibling_iterator j; for (auto& g: children) { - ordered_forest<V, Allocator> c(std::move(g.f_)); + ordered_forest<V, Allocator> c(g.f_); j = j? f_.graft_after(j, std::move(c)): sibling_iterator(f_.graft_child(top, std::move(c))); } } diff --git a/cmake/FindPythonModule.cmake b/cmake/FindPythonModule.cmake index 90484e43..d59df594 100644 --- a/cmake/FindPythonModule.cmake +++ b/cmake/FindPythonModule.cmake @@ -2,7 +2,6 @@ include(FindPackageHandleStandardArgs) function(find_python_module module) string(TOUPPER ${module} module_upper) - if(NOT PY_${module_upper}) if(ARGC GREATER 1 AND ARGV1 STREQUAL "REQUIRED") set(${module}_FIND_REQUIRED TRUE) diff --git a/python/schedule.hpp b/python/schedule.hpp index d7369674..619f7723 100644 --- a/python/schedule.hpp +++ b/python/schedule.hpp @@ -81,7 +81,7 @@ struct poisson_schedule_shim: schedule_shim_base { arb::time_type tstart; // ms arb::time_type freq; // kHz - opt_time_type tstop = {}; // ms + opt_time_type tstop; // ms rng_type::result_type seed; poisson_schedule_shim(arb::time_type ts, arb::time_type f, rng_type::result_type s, pybind11::object tstop); -- GitLab