From b9138fb12b0cef77621ed3a5eba577ebe4f7abd0 Mon Sep 17 00:00:00 2001 From: Gaurav Kumar <84905312+GauravKumar9920@users.noreply.github.com> Date: Tue, 2 Apr 2024 05:41:32 +0530 Subject: [PATCH] Fixed undefined behavior in thruster.cc (#2350) --------- Signed-off-by: Gaurav Kumar Co-authored-by: Arjo Chakravarty --- test/integration/thruster.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/integration/thruster.cc b/test/integration/thruster.cc index 3a365ea69f..c4d4ec4d08 100644 --- a/test/integration/thruster.cc +++ b/test/integration/thruster.cc @@ -211,6 +211,7 @@ void ThrusterTest::TestWorld(const std::string &_world, // Check no movement because of invalid commands fixture.Server()->Run(true, 100, false); + ASSERT_FALSE(modelPoses.empty()); EXPECT_DOUBLE_EQ(0.0, modelPoses.back().Pos().X()); EXPECT_EQ(100u, modelPoses.size()); EXPECT_EQ(100u, propellerAngVels.size()); @@ -244,8 +245,8 @@ void ThrusterTest::TestWorld(const std::string &_world, // Check movement if (_namespace != "lowbattery") { - for (sleep = 0; modelPoses.back().Pos().X() < 5.0 && sleep < maxSleep; - ++sleep) + for (sleep = 0; (modelPoses.empty() || modelPoses.back().Pos().X() < 5.0) && + sleep < maxSleep; ++sleep) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); fixture.Server()->Run(true, 100, false); @@ -331,13 +332,11 @@ void ThrusterTest::TestWorld(const std::string &_world, EXPECT_NEAR(0.0, angVel.Y(), _baseTol); EXPECT_NEAR(0.0, angVel.Z(), _baseTol); } - modelPoses.clear(); propellerAngVels.clear(); propellerLinVels.clear(); // Make sure that when the deadband is disabled // commands below the deadband should create a movement - auto latest_pose = modelPoses.back(); msgs::Boolean db_msg; if (_namespace == "deadband") {