From d74e003b215b64a4d287deb1e62d8b1ec6d42367 Mon Sep 17 00:00:00 2001 From: Changgyu Choi Date: Tue, 5 Oct 2021 17:09:55 +0900 Subject: [PATCH] Fix static issue Change-Id: I49a20746e2261d64df716e2a949c914ec56f553b Signed-off-by: Changgyu Choi --- idlc/gen/cpp_gen_base.cc | 6 +++++- idlc/gen/cs_gen_base.cc | 5 ++++- unit_tests/type_unittest.cc | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/idlc/gen/cpp_gen_base.cc b/idlc/gen/cpp_gen_base.cc index 1e45d27..77f8ad5 100644 --- a/idlc/gen/cpp_gen_base.cc +++ b/idlc/gen/cpp_gen_base.cc @@ -368,7 +368,11 @@ void CppGeneratorBase::GenListSerializer(std::ofstream& stream, << NLine(1); stream << Tab(1) << "for (const auto& i : c) "; GenBrace(stream, TAB_SIZE, [&]() { - auto& mt = *type.GetMetaType(); + auto* ptr = type.GetMetaType(); + if (ptr == nullptr) + return; + + auto& mt = *ptr; stream << AddIndent(TAB_SIZE * 2, ConvertTypeToSerializer(mt, "i", "h")); }, false); stream << Tab(1) << "return h;" << NLine(1); diff --git a/idlc/gen/cs_gen_base.cc b/idlc/gen/cs_gen_base.cc index 480fda8..2507315 100644 --- a/idlc/gen/cs_gen_base.cc +++ b/idlc/gen/cs_gen_base.cc @@ -163,7 +163,10 @@ void CsGeneratorBase::GenListSerializer(std::ofstream& stream, << NLine(1); stream << Tab(4) << "foreach (var i in param)" << NLine(1); GenBrace(stream, TAB_SIZE * 4, [&]() { - auto& mt = *type.GetMetaType(); + auto* ptr = type.GetMetaType(); + if (ptr == nullptr) return; + + auto& mt = *ptr; if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) { stream << Tab(5) << "h.Write" << ConvertTypeToParcelType(mt.ToString()) diff --git a/unit_tests/type_unittest.cc b/unit_tests/type_unittest.cc index f08e7b3..677e096 100644 --- a/unit_tests/type_unittest.cc +++ b/unit_tests/type_unittest.cc @@ -61,6 +61,7 @@ TEST_F(BaseTypeTest, BaseType_Constructor) { TEST_F(BaseTypeTest, BaseType_SetMetaType) { tidl::BaseType* customType = new tidl::BaseType("CustomType", "", true); customType->SetMetaType(new tidl::BaseType("int", "")); + EXPECT_NE(customType->GetMetaType(), nullptr); EXPECT_EQ(customType->GetMetaType()->ToString(), "int"); delete customType; } @@ -68,6 +69,7 @@ TEST_F(BaseTypeTest, BaseType_SetMetaType) { TEST_F(BaseTypeTest, BaseType_GetMetaType) { tidl::BaseType* customType = new tidl::BaseType("CustomType", "", true); customType->SetMetaType(new tidl::BaseType("string", "")); + EXPECT_NE(customType->GetMetaType(), nullptr); EXPECT_EQ(customType->GetMetaType()->ToString(), "string"); delete customType; } -- 2.7.4