Skip to content

Commit 95a3ecf

Browse files
Add extra check to checkExpectedBeamThroughEntity to fix segfault (#61)
2 parents 5b2d347 + 7af2446 commit 95a3ecf

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

ed_sensor_integration/include/ed/kinect/fitter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ class Fitter
233233

234234
/**
235235
* @brief checkExpectedBeamThroughEntity checks if the expected center beam passes through the entity. If
236-
* not: something went wrong
236+
* not: throw a fitter error
237237
* @param model_ranges
238238
* @param entity
239239
* @param sensor_pose_xya
240-
* @param expected_center_beam
240+
* @param expected_center_beam expected index of the beam through the center of the object. range: any int. indices outside bounds will also throw an error.
241241
*/
242242
void checkExpectedBeamThroughEntity(const std::vector<double> &model_ranges, ed::EntityConstPtr entity,
243243
const geo::Pose3D &sensor_pose_xya, const int expected_center_beam) const;

ed_sensor_integration/src/kinect/fitter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ std::unique_ptr<OptimalFit> Fitter::findOptimum(const EstimationInputData& input
377377
}
378378
if (valid_optimum)
379379
return current_optimum;
380+
381+
ROS_ERROR_NAMED("fitter", "optimum is invalid");
380382
std::unique_ptr<OptimalFit> invalid_optimum(new OptimalFit);
381383
return invalid_optimum;
382384
}
@@ -462,7 +464,8 @@ void Fitter::checkExpectedBeamThroughEntity(const std::vector<double>& model_ran
462464
expected_ranges = model_ranges;
463465
std::vector<int> expected_identifiers(nr_data_points_, 0);
464466
renderEntity(entity, sensor_pose_xya, 1, expected_ranges, expected_identifiers);
465-
467+
if (expected_center_beam < 0 || expected_center_beam >= nr_data_points_)
468+
throw FitterError("Expected beam outside of measurement range(" + std::to_string(nr_data_points_) + "), index: " + std::to_string(expected_center_beam));
466469
if (expected_identifiers[expected_center_beam] != 1) // expected center beam MUST contain the rendered model
467470
throw FitterError("Expected beam does not go through entity");
468471
}

0 commit comments

Comments
 (0)