From d092e767ea51a22cf91e001154a545a847373188 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Sat, 13 Aug 2022 16:59:08 +1000 Subject: [PATCH] AP_Common: correct gtests AFAIK it's invalid to new a zero-length array. --- libraries/AP_Common/tests/test_cpp.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/AP_Common/tests/test_cpp.cpp b/libraries/AP_Common/tests/test_cpp.cpp index d6946ae0aa..9ffe282bbd 100644 --- a/libraries/AP_Common/tests/test_cpp.cpp +++ b/libraries/AP_Common/tests/test_cpp.cpp @@ -10,17 +10,17 @@ public: TEST(AP_Common, TEST_CPP) { - DummyDummy * test_new = new DummyDummy[0]; + DummyDummy * test_new = new DummyDummy[1]; EXPECT_FALSE(test_new == nullptr); EXPECT_TRUE(sizeof(test_new) == 8); - EXPECT_EQ(test_new->count, 0); - EXPECT_FLOAT_EQ(test_new->d, 0); + EXPECT_FLOAT_EQ(test_new->count, 1); + EXPECT_FLOAT_EQ(test_new->d, 42.0); - DummyDummy * test_d = (DummyDummy*) ::operator new (0); + DummyDummy * test_d = (DummyDummy*) ::operator new (sizeof(DummyDummy)); EXPECT_FALSE(test_d == nullptr); EXPECT_TRUE(sizeof(test_d) == 8); - EXPECT_EQ(test_d->count, 0); - EXPECT_FLOAT_EQ(test_d->d, 0); + EXPECT_EQ(test_d->count, 0); // constructor isn't called + EXPECT_FLOAT_EQ(test_d->d, 0.0); DummyDummy * test_d2 = new DummyDummy; EXPECT_TRUE(sizeof(test_d2) == 8); @@ -32,4 +32,4 @@ TEST(AP_Common, TEST_CPP) delete test_d2; } -AP_GTEST_MAIN() \ No newline at end of file +AP_GTEST_MAIN()