You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The function getMaxValue and getMinValue have a bug. When called with an empty vector they crash the program.
This is caused by the lines below.
std::min_element and std::max_element, when called with two identical iterators (which happens when we call begin() and end() on an empty vector), return this iterator. De-referencing an end() iterator causes the program to crash.
This case should be considered e.g. with an early return that returns nan when the vector is empty, or throwing an exception.
Context:
I am adding unit tests for the geometry package and wanted to add tests for the aforementioned functions, but calling them with an empty vector causes the whole program to crash.
To Reproduce
Steps to reproduce the behavior:
Edit any existing source code file or add a new one
Call getMinValue or getMaxValue with an empty vector as argument
Compile and execute
See error
Expected behavior
Some controlled handling of the empty vector situation like return of nan or throwing an exception, but not program crash.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
OS: [e.g. iOS]: Ubuntu
Browser [e.g. chrome, safari]: Firefox
Version [e.g. 22]: 22
ROS 2 version: Humble
DDS: CycloneDDS
The text was updated successfully, but these errors were encountered:
Thanks, please use THROW_SIMULATION_ERROR macro when the length of the points are zero.
And, if the length of the points are one, return the first points.
Describe the bug
The function
getMaxValue
andgetMinValue
have a bug. When called with an empty vector they crash the program.This is caused by the lines below.
scenario_simulator_v2/common/math/geometry/src/polygon/polygon.cpp
Line 55 in 173a8c1
scenario_simulator_v2/common/math/geometry/src/polygon/polygon.cpp
Line 61 in 173a8c1
std::min_element
andstd::max_element
, when called with two identical iterators (which happens when we callbegin()
andend()
on an empty vector), return this iterator. De-referencing anend()
iterator causes the program to crash.This case should be considered e.g. with an early return that returns
nan
when the vector is empty, or throwing an exception.Context:
I am adding unit tests for the
geometry
package and wanted to add tests for the aforementioned functions, but calling them with an empty vector causes the whole program to crash.To Reproduce
Steps to reproduce the behavior:
getMinValue
orgetMaxValue
with an empty vector as argumentExpected behavior
Some controlled handling of the empty vector situation like return of
nan
or throwing an exception, but not program crash.Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: