Fix static issue 27/264927/3
authorChanggyu Choi <changyu.choi@samsung.com>
Tue, 5 Oct 2021 08:09:55 +0000 (17:09 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Tue, 5 Oct 2021 08:18:12 +0000 (17:18 +0900)
Change-Id: I49a20746e2261d64df716e2a949c914ec56f553b
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
idlc/gen/cpp_gen_base.cc
idlc/gen/cs_gen_base.cc
unit_tests/type_unittest.cc

index 1e45d27..77f8ad5 100644 (file)
@@ -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);
index 480fda8..2507315 100644 (file)
@@ -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())
index f08e7b3..677e096 100644 (file)
@@ -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;
 }