Skip to content

Commit

Permalink
Enhance code security
Browse files Browse the repository at this point in the history
  • Loading branch information
Grufoony committed Feb 3, 2025
1 parent f51bbf7 commit 422f160
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/dsm/headers/Dynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ namespace dsm {
template <typename agent_t>
void Dynamics<agent_t>::removeAgent(Size agentId) {
m_agents.erase(agentId);
Logger::debug(std::format("Removed agent with id {}", agentId));
}

template <typename agent_t>
Expand Down
13 changes: 8 additions & 5 deletions src/dsm/headers/RoadDynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ namespace dsm {
}
}
}
assert(possibleMoves.size() > 0);
if (possibleMoves.empty()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 14.4 rule Note

MISRA 14.4 rule
Logger::error(
std::format("No possible moves from node {} for agent {}", nodeId, agentId));
}
std::uniform_int_distribution<Size> moveDist{
0, static_cast<Size>(possibleMoves.size() - 1)};
uint8_t p{0};
Expand Down Expand Up @@ -333,7 +336,7 @@ namespace dsm {
}
continue;
}
auto const& nextStreet{this->m_graph.streetSet()[m_agentNextStreetId[agentId]]};
auto const& nextStreet{this->m_graph.street(m_agentNextStreetId.at(agentId))};
if (nextStreet->isFull()) {
continue;
}
Expand Down Expand Up @@ -362,7 +365,7 @@ namespace dsm {
return false;
}
for (auto const [angle, agentId] : intersection.agents()) {
auto const& nextStreet{this->m_graph.streetSet()[m_agentNextStreetId[agentId]]};
auto const& nextStreet{this->m_graph.street(m_agentNextStreetId.at(agentId))};
if (nextStreet->isFull()) {
if (m_forcePriorities) {
return false;
Expand All @@ -385,7 +388,7 @@ namespace dsm {
return false;
}
auto const agentId{roundabout.agents().front()};
auto const& nextStreet{this->m_graph.streetSet()[m_agentNextStreetId[agentId]]};
auto const& nextStreet{this->m_graph.street(m_agentNextStreetId.at(agentId))};
if (!(nextStreet->isFull())) {
if (this->agents().at(agentId)->streetId().has_value()) {
const auto streetId = this->agents().at(agentId)->streetId().value();
Expand Down Expand Up @@ -496,7 +499,7 @@ namespace dsm {
!m_agentNextStreetId.contains(agentId)) {
Id srcNodeId = agent->srcNodeId().has_value() ? agent->srcNodeId().value()
: nodeDist(this->m_generator);
const auto& srcNode{this->m_graph.nodeSet()[srcNodeId]};
const auto& srcNode{this->m_graph.node(srcNodeId)};
if (srcNode->isFull()) {
continue;
}
Expand Down

0 comments on commit 422f160

Please sign in to comment.