fix msp_osd: ASAN raised some buffer overflows when running the unit tests

This commit is contained in:
Beat Küng
2025-06-16 15:50:41 +02:00
parent 8370ae1701
commit 6ce1634dea
@@ -54,7 +54,6 @@ public:
{ {
// construct new default display // construct new default display
md_ = std::make_unique<MessageDisplay>(PERIOD, DWELL); md_ = std::make_unique<MessageDisplay>(PERIOD, DWELL);
return;
} }
}; };
@@ -65,7 +64,7 @@ TEST_F(MessageDisplayTest, testMessageDisplayConstruction)
ASSERT_TRUE(static_cast<bool>(md_)); ASSERT_TRUE(static_cast<bool>(md_));
// verify default message // verify default message
char message[FULL_MSG_LENGTH]; char message[FULL_MSG_BUFFER];
md_->get(message, 0); md_->get(message, 0);
EXPECT_STREQ(message, "INITIALIZING"); EXPECT_STREQ(message, "INITIALIZING");
} }
@@ -150,6 +149,7 @@ TEST_F(MessageDisplayTest, testMessageDisplayWarning)
// get substring that we should be seeing // get substring that we should be seeing
strncpy(correct, &ground_truth[i], FULL_MSG_LENGTH); strncpy(correct, &ground_truth[i], FULL_MSG_LENGTH);
correct[FULL_MSG_BUFFER - 1] = '\0';
EXPECT_STREQ(message, correct); EXPECT_STREQ(message, correct);
// update time // update time
@@ -159,5 +159,6 @@ TEST_F(MessageDisplayTest, testMessageDisplayWarning)
// verify that we wrap around as expected at the end // verify that we wrap around as expected at the end
md_->get(message, stamp); md_->get(message, stamp);
strncpy(correct, ground_truth, FULL_MSG_LENGTH); strncpy(correct, ground_truth, FULL_MSG_LENGTH);
correct[FULL_MSG_BUFFER - 1] = '\0';
EXPECT_STREQ(message, correct); EXPECT_STREQ(message, correct);
} }