Fix crash issue 09/270009/2
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 24 Jan 2022 06:34:41 +0000 (15:34 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 24 Jan 2022 06:36:54 +0000 (15:36 +0900)
Before calling Add() method, the ptr should be checked.

Change-Id: I1cf5e1c95f2eb104778e9352f758819b51a9780c
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
idlc/ast/tidlc.yy

index cfb1caf60fc6b8837e4ff74e06a2d3f6eafcf8a0..7a0cf65ef46b0ebb0f08e036c9dc249ad75935bb 100644 (file)
@@ -152,7 +152,9 @@ structure_block: T_STRUCTURE T_ID T_BRACE_OPEN elements T_BRACE_CLOSE {
 elements: element {
     $$ = new (std::nothrow) tidl::Elements();
     if ($$ != nullptr) {
-      $$->Add(std::unique_ptr<tidl::Element>($1));
+      if ($1 != nullptr) {
+        $$->Add(std::unique_ptr<tidl::Element>($1));
+      }
     }
   }
   | elements element {
@@ -194,7 +196,9 @@ element: raw_type T_ID T_SEMICOLON {
 attributes: attribute {
     $$ = new (std::nothrow) tidl::Attributes();
     if ($$ != nullptr) {
-      $$->Add(std::unique_ptr<tidl::Attribute>($1));
+      if ($1 != nullptr) {
+        $$->Add(std::unique_ptr<tidl::Attribute>($1));
+      }
     }
   }
   | attributes T_COMMA attribute {
@@ -266,7 +270,9 @@ interface_block: T_INTERFACE T_ID T_BRACE_OPEN declarations T_BRACE_CLOSE {
 declarations: declaration {
     $$ = new (std::nothrow) tidl::Declarations();
     if ($$ != nullptr) {
-      $$->Add(std::unique_ptr<tidl::Declaration>($1));
+      if ($1 != nullptr) {
+        $$->Add(std::unique_ptr<tidl::Declaration>($1));
+      }
     }
   }
   | declarations declaration {
@@ -361,8 +367,10 @@ declaration: base_type T_ID T_LEFT parameter_list T_RIGHT T_SEMICOLON {
 
 parameter_list: parameter {
     $$ = new tidl::Parameters();
-    if ($1 != nullptr) {
-      $$->Add(std::unique_ptr<tidl::Parameter>($1));
+    if ($$ != nullptr) {
+      if ($1 != nullptr) {
+        $$->Add(std::unique_ptr<tidl::Parameter>($1));
+      }
     }
   }
   | parameter_list T_COMMA parameter {