Skip to content

Commit

Permalink
Fix a few easy to fix issues flagged by coverity (AIDASoft#535)
Browse files Browse the repository at this point in the history
* Use std::move in some places that coverity flagged

* Fix resource leak discovered by coverity

* Fix copy-paste error discovered by coverity

* Restore ostream state as discovered by coverity
  • Loading branch information
tmadlener authored Dec 19, 2023
1 parent a820fb1 commit 308b33f
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/podio/Frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class Frame {
*/
template <typename T, typename = podio::EnableIfValidGenericDataType<T>>
inline void putParameter(const std::string& key, T value) {
m_self->parameters().setValue(key, value);
m_self->parameters().setValue(key, std::move(value));
}

/** Add a string value to the parameters of the Frame by copying it. Dedicated
Expand Down
2 changes: 1 addition & 1 deletion include/podio/GenericParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void GenericParameters::setValue(const std::string& key, T value) {
map.insert_or_assign(key, std::move(value));
} else {
// Wrap the value into a vector with exactly one entry and store that
std::vector<T> v = {value};
std::vector<T> v = {std::move(value)};
std::lock_guard lock{mtx};
map.insert_or_assign(key, std::move(v));
}
Expand Down
2 changes: 1 addition & 1 deletion include/podio/ROOTFrameData.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ROOTFrameData {
ROOTFrameData& operator=(const ROOTFrameData&) = delete;

ROOTFrameData(BufferMap&& buffers, CollIDPtr&& idTable, podio::GenericParameters&& params) :
m_buffers(std::move(buffers)), m_idTable(idTable), m_parameters(std::move(params)) {
m_buffers(std::move(buffers)), m_idTable(std::move(idTable)), m_parameters(std::move(params)) {
}

std::optional<podio::CollectionReadBuffers> getCollectionBuffers(const std::string& name) {
Expand Down
4 changes: 2 additions & 2 deletions include/podio/SIOBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ class SIOCollectionIDTableBlock : public sio::block {
void read(sio::read_device& device, sio::version_type version) override;
void write(sio::write_device& device) override;

podio::CollectionIDTable* getTable() {
return new podio::CollectionIDTable(std::move(_ids), std::move(_names));
podio::CollectionIDTable getTable() {
return podio::CollectionIDTable(std::move(_ids), std::move(_names));
}
const std::vector<std::string>& getTypeNames() const {
return _types;
Expand Down
2 changes: 1 addition & 1 deletion python/templates/macros/implementations.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Mutable{{ type }} {{ full_type }}::clone() const {
return Mutable{{ type }}(podio::utils::MaybeSharedPtr(new {{ type }}Obj(*m_obj), podio::utils::MarkOwned));
}

{{ full_type }}::{{ full_type }}(podio::utils::MaybeSharedPtr<{{ type }}Obj> obj) : m_obj(obj) {}
{{ full_type }}::{{ full_type }}(podio::utils::MaybeSharedPtr<{{ type }}Obj> obj) : m_obj(std::move(obj)) {}

{%- endmacro %}

Expand Down
3 changes: 3 additions & 0 deletions src/GenericParameters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ std::ostream& operator<<(std::ostream& os, const std::vector<T>& values) {

template <typename MapType>
void printMap(const MapType& map, std::ostream& os) {
const auto osflags = os.flags();
os << std::left << std::setw(30) << "Key "
<< "Value " << '\n';
os << "--------------------------------------------------------------------------------\n";
for (const auto& [key, value] : map) {
os << std::left << std::setw(30) << key << value << '\n';
}

os.flags(osflags);
}

void GenericParameters::print(std::ostream& os, bool flush) {
Expand Down
2 changes: 1 addition & 1 deletion src/SIOFrameData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void SIOFrameData::readIdTable() {
sio::api::read_blocks(uncBuffer.span(), blocks);

auto* idTableBlock = static_cast<SIOCollectionIDTableBlock*>(blocks[0].get());
m_idTable = std::move(*idTableBlock->getTable());
m_idTable = idTableBlock->getTable();
m_typeNames = idTableBlock->getTypeNames();
m_subsetCollectionBits = idTableBlock->getSubsetCollectionBits();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/read_python_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int checkHits(const ExampleHitCollection& hits) {
auto hit2 = hits[1];
if (hit2.cellID() != 0xcaffee || hit2.x() != 1.0 || hit2.y() != 0.0 || hit2.z() != 0.0 || hit2.energy() != 12.0) {
std::cerr << "Could not retrieve the correct hit[1]: (expected: "
<< MutableExampleHit(0xcaffee, 1.0, 0.0, 0.0, 12.0) << ", actual: " << hit1 << ")" << std::endl;
<< MutableExampleHit(0xcaffee, 1.0, 0.0, 0.0, 12.0) << ", actual: " << hit2 << ")" << std::endl;
return 1;
}

Expand Down

0 comments on commit 308b33f

Please sign in to comment.