Skip to content

Commit

Permalink
Fixed undefined behavior in thruster.cc (#2350)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Gaurav Kumar <[email protected]>
Co-authored-by: Arjo Chakravarty <[email protected]>
  • Loading branch information
GauravKumar9920 and arjo129 authored Apr 2, 2024
1 parent 760ba21 commit b9138fb
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions test/integration/thruster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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")
{
Expand Down

0 comments on commit b9138fb

Please sign in to comment.