Fix C Generator 45/261145/1
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 12 Jul 2021 10:10:31 +0000 (19:10 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Mon, 12 Jul 2021 10:12:06 +0000 (19:12 +0900)
This patch adds the return value check of the clone function.
If calling the function returns a negative error value, the generated
function returns a negative error value.

Change-Id: I114bb62990413e4e1bfa99625dc6686c65214fd1
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
idlc/gen/c_body_gen_base.cc
idlc/gen/c_body_gen_base_cb.h

index 50f61bb..29b01e9 100644 (file)
@@ -733,11 +733,11 @@ std::string CBodyGeneratorBase::GetFinalizeString(const std::string& id,
         [&]()->std::string {
           return GenTemplateString(CB_IF_STATEMENT,
               [&]()->std::string {
-                return handle + id + "[i]";
+                return handle + id + "[j]";
               },
               [&]()->std::string {
                 return GetDestructorString(*type.GetMetaType(),
-                    handle + id + "[i]", true) + NLine(1);
+                    handle + id + "[j]", true) + NLine(1);
               });
         },
         [&]()->std::string {
@@ -843,8 +843,24 @@ std::string CBodyGeneratorBase::GetSetterString(const std::string& id,
     str += NLine(1);
     str += GenTemplateString(ReplaceAll(CB_SETTER_ARRAY_BLOCK, "##", id),
         [&]()->std::string {
-          return GetSetterString(*type.GetMetaType(),
-              "h->" + id + "[i]", id + "[i]");
+          std::string s;
+          s += "int __ret = ";
+          s += GetSetterString(*type.GetMetaType(), "h->" + id + "[i]",
+              id + "[i]");
+          s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+              [&]()->std::string {
+                return "__ret != 0";
+              },
+              [&]()->std::string {
+                std::string r;
+                r += "_E(\"Failed to clone " + id + "\");" + NLine(1);
+                r += GetFinalizeString(id, type, "h->") + NLine(1);
+                r += GetSetterString("h->" + id, "NULL") + NLine(1);
+                r += "return -1;";
+                return r;
+              });
+          s += NLine(1);
+          return s;
         });
   } else {
     str += GetSetterString(type, "h->" + id, id);
@@ -860,8 +876,24 @@ std::string CBodyGeneratorBase::GetGetterString(const std::string& id,
   if (type.ToString() == "array") {
     str += GenTemplateString(ReplaceAll(CB_GETTER_ARRAY_BLOCK, "##", id),
         [&]()->std::string {
-           return GetSetterString(*type.GetMetaType(),
+          std::string s;
+          s += "int __ret = ";
+          s += GetSetterString(*type.GetMetaType(),
               "(*" + id + ")[i]", "h->" + id + "[i]");
+          s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+              [&]()->std::string {
+                return "__ret != 0";
+              },
+              [&]()->std::string {
+                std::string r;
+                r += "_E(\"Failed to clone " + id + "\");" + NLine(1);
+                r += GetFinalizeString(id, type, "h->") + NLine(1);
+                r += GetSetterString("h->" + id, "NULL") + NLine(1);
+                r += "return -1;";
+                return r;
+              });
+          s += NLine(1);
+          return s;
         });
   } else {
     if (type.IsUserDefinedType() ||
@@ -1035,8 +1067,24 @@ std::string CBodyGeneratorBase::GetClonerString(const std::string& id,
           return GetStructIdWithNamespace(st);
         },
         [&]()->std::string {
-           return GetSetterString(*type.GetMetaType(),
+          std::string s;
+          s += "int __ret = ";
+          s += GetSetterString(*type.GetMetaType(),
               "handle->" + id + "[i]", "h->" + id + "[i]");
+          s += GenTemplateString(CB_IF_STATEMENT_WITH_BRACES,
+              [&]()->std::string {
+                return "__ret != 0";
+              },
+              [&]()->std::string {
+                std::string tmp;
+                tmp += "_E(\"Failed to clone " + id + "\");" + NLine(1);
+                tmp += "rpc_port_" + GetStructIdWithNamespace(st) +
+                    "_destroy(handle);" + NLine(1);
+                tmp += "return -1;";
+                return tmp;
+              });
+          s += NLine(1);
+          return s;
         });
   } else {
     str += GetSetterString(type, "handle->" + id, "h->" + id);
index a9d7ef1..e9bcc76 100644 (file)
@@ -287,7 +287,7 @@ do {
 const char CB_FINALIZE_ARRAY_BLOCK[] =
 R"__c_cb(
 do {
-    for (int i = 0; i < $$; i++) {
+    for (int j = 0; j < $$; j++) {
         $$
     }
     free($$);