From 907520aad69bb62af241dd32dc1f8f6754a5d482 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Mon, 22 Nov 2021 10:36:37 +0900 Subject: [PATCH] Fix static anlaysis issues - DEREF_OF_NULL - UNINIT Change-Id: Id12b76a7d40a9a7df299b03c9aed2f10209d99df Signed-off-by: Hwankyu Jhun --- idlc/gen/cpp_stub_header_gen_cb.h | 2 +- idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h | 18 ++++++++++++++---- idlc/gen_cion/cpp_cion_proxy_header_gen_cb.h | 5 +++-- idlc/gen_cion/java_cion_gen_base.cc | 26 +++++++++++--------------- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/idlc/gen/cpp_stub_header_gen_cb.h b/idlc/gen/cpp_stub_header_gen_cb.h index 4648c3c..49158c2 100644 --- a/idlc/gen/cpp_stub_header_gen_cb.h +++ b/idlc/gen/cpp_stub_header_gen_cb.h @@ -123,7 +123,7 @@ R"__cpp_cb( private: std::string sender_; std::string instance_; - rpc_port_h port_; + rpc_port_h port_ = nullptr; std::unique_ptr active_object_; };)__cpp_cb"; diff --git a/idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h b/idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h index 294df1f..64b1dd3 100644 --- a/idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h +++ b/idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h @@ -345,14 +345,21 @@ $$::$$(IEventListener* listener, const std::string& service_name, _E("Failed to create security handle. error(%d)", ret); throw InvalidIOException(); } + auto security_auto = std::unique_ptr< + std::remove_pointer::type, decltype(cion_security_destroy)*>( + security, cion_security_destroy); - ret = cion_client_create(&cion_client_, service_name.c_str(), security); + cion_client_h client = nullptr; + ret = cion_client_create(&client, service_name.c_str(), security); if (ret != CION_ERROR_NONE) { _E("Failed to create handle. error(%d)", ret); throw InvalidIOException(); } + auto client_auto = std::unique_ptr< + std::remove_pointer::type, decltype(cion_client_destroy)*>( + client, cion_client_destroy); - ret = cion_client_add_disconnected_cb(cion_client_, OnDisconnectedCB, + ret = cion_client_add_disconnected_cb(client, OnDisconnectedCB, this); if (ret != CION_ERROR_NONE) { _E("Failed to cion_client_add_disconnected_cb. error(%d)", ret); @@ -360,19 +367,22 @@ $$::$$(IEventListener* listener, const std::string& service_name, } - ret = cion_client_add_connection_result_cb(cion_client_, OnConnectionResultCB, + ret = cion_client_add_connection_result_cb(client, OnConnectionResultCB, this); if (ret != CION_ERROR_NONE) { _E("Failed to cion_client_add_connection_result_cb. error(%d)", ret); throw InvalidIOException(); } - ret = cion_client_add_payload_received_cb(cion_client_, OnPayloadReceivedCB, + ret = cion_client_add_payload_received_cb(client, OnPayloadReceivedCB, this); if (ret != CION_ERROR_NONE) { _E("Failed to cion_client_add_payload_received_cb. error(%d)", ret); throw InvalidIOException(); } + + cion_security_ = security_auto.release(); + cion_client_ = client_auto.release(); } )__cpp_cb"; diff --git a/idlc/gen_cion/cpp_cion_proxy_header_gen_cb.h b/idlc/gen_cion/cpp_cion_proxy_header_gen_cb.h index 9a73fcd..683f5b9 100644 --- a/idlc/gen_cion/cpp_cion_proxy_header_gen_cb.h +++ b/idlc/gen_cion/cpp_cion_proxy_header_gen_cb.h @@ -141,8 +141,9 @@ R"__cpp_cb( void ProcessReceivedEvent(rpc_port_parcel_h parcel); cion_payload_transfer_status_e status, void *user_data); - cion_client_h cion_client_; - cion_peer_info_h peer_; + cion_client_h cion_client_ = nullptr; + cion_security_h cion_security_ = nullptr; + cion_peer_info_h peer_ = nullptr; IEventListener* listener_; std::string service_name_; std::string target_appid_; diff --git a/idlc/gen_cion/java_cion_gen_base.cc b/idlc/gen_cion/java_cion_gen_base.cc index 3ba497a..409a0c7 100644 --- a/idlc/gen_cion/java_cion_gen_base.cc +++ b/idlc/gen_cion/java_cion_gen_base.cc @@ -305,20 +305,21 @@ void JavaCionGeneratorBase::GenSerializer(std::ofstream& stream) { void JavaCionGeneratorBase::GenListSerializer(std::ofstream& stream, const BaseType& type) { + auto* ptr = type.GetMetaType(); + if (ptr == nullptr) + return; + + auto& mt = *ptr; stream << Tab(1) << "private static void serialize(CionParcel h, " << ConvertTypeToString(type) << " param, " - << ConvertTypeToString(*(type.GetMetaType()), true) << " a) "; + << ConvertTypeToString(mt, true) << " a) "; GenBrace(stream, TAB_SIZE, [&]() { stream << Tab(2) << "h.write(param.size());" << NLine(1); - stream << Tab(2) << "for (" << ConvertTypeToString(*(type.GetMetaType()), true) + stream << Tab(2) << "for (" << ConvertTypeToString(mt, true) << " i : param) "; GenBrace(stream, TAB_SIZE * 2, [&]() { - auto* ptr = type.GetMetaType(); - if (ptr == nullptr) return; - - auto& mt = *ptr; if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) { stream << Tab(3) << "h.write(i);" << NLine(1); } else { @@ -334,25 +335,20 @@ void JavaCionGeneratorBase::GenListSerializer(std::ofstream& stream, stream << Tab(1) << "private static void deserialize(CionParcel h, " << ConvertTypeToString(type) << " param, " - << ConvertTypeToString(*(type.GetMetaType()), true) << " a) "; + << ConvertTypeToString(mt, true) << " a) "; GenBrace(stream, TAB_SIZE, [&]() { stream << Tab(2) << "int l = h.readInt();" << NLine(1); stream << Tab(2) << "for (int i = 0; i < l; i++) "; GenBrace(stream, TAB_SIZE * 2, [&]() { - auto* ptr = type.GetMetaType(); - if (ptr == nullptr) - return; - - auto& mt = *ptr; - if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) { - stream << Tab(3) << ConvertTypeToString(*(type.GetMetaType()), true) + if (!mt.IsUserDefinedType() && mt.GetMetaType() == nullptr) { + stream << Tab(3) << ConvertTypeToString(mt, true) << " v = h.read" << ConvertTypeToParcelType(mt.ToString()) << "();" << NLine(1); } else { - stream << Tab(3) << ConvertTypeToString(*(type.GetMetaType()), true) + stream << Tab(3) << ConvertTypeToString(mt, true) << " v = new " << ConvertTypeToString(mt) << "();" << NLine(1); if (mt.GetMetaType() != nullptr) { -- 2.7.4