From 6ce1634deae53363aa40a08f493e75802f2b1917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Mon, 16 Jun 2025 15:50:41 +0200 Subject: [PATCH] fix msp_osd: ASAN raised some buffer overflows when running the unit tests --- .../osd/msp_osd/MessageDisplay/MessageDisplayTest.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/drivers/osd/msp_osd/MessageDisplay/MessageDisplayTest.cpp b/src/drivers/osd/msp_osd/MessageDisplay/MessageDisplayTest.cpp index 1db76d01b3..11b05f45db 100644 --- a/src/drivers/osd/msp_osd/MessageDisplay/MessageDisplayTest.cpp +++ b/src/drivers/osd/msp_osd/MessageDisplay/MessageDisplayTest.cpp @@ -54,7 +54,6 @@ public: { // construct new default display md_ = std::make_unique(PERIOD, DWELL); - return; } }; @@ -65,7 +64,7 @@ TEST_F(MessageDisplayTest, testMessageDisplayConstruction) ASSERT_TRUE(static_cast(md_)); // verify default message - char message[FULL_MSG_LENGTH]; + char message[FULL_MSG_BUFFER]; md_->get(message, 0); EXPECT_STREQ(message, "INITIALIZING"); } @@ -150,6 +149,7 @@ TEST_F(MessageDisplayTest, testMessageDisplayWarning) // get substring that we should be seeing strncpy(correct, &ground_truth[i], FULL_MSG_LENGTH); + correct[FULL_MSG_BUFFER - 1] = '\0'; EXPECT_STREQ(message, correct); // update time @@ -159,5 +159,6 @@ TEST_F(MessageDisplayTest, testMessageDisplayWarning) // verify that we wrap around as expected at the end md_->get(message, stamp); strncpy(correct, ground_truth, FULL_MSG_LENGTH); + correct[FULL_MSG_BUFFER - 1] = '\0'; EXPECT_STREQ(message, correct); }