diff --git a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp index ae595b0af0476b21cc7374b759c8f82ad5c9be85..b1e43ee23d324f212bd45006221f89de6fb37be4 100644 --- a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp +++ b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp @@ -30,7 +30,7 @@ namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(DHFWKSAManager); DHFWKSAManager::DHFWKSAManager() : dhfwkOnLine_(false), isSubscribeDHFWKSAChangeListener(false), dhfwkProxy_(nullptr), - saListener_(new SystemAbilityListener()), saStateCallback(nullptr), + saListener_(sptr(new SystemAbilityListener())), saStateCallback(nullptr), publisherListenersCache_({}), avTransControlCenterCbCache_({}) { DHLOGI("Ctor DHFWKSAManager"); diff --git a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp index 1e48f2812ae73d6ba7fa39fdf943f91464455aaa..2ec30f8c840419326556bd3d68aedaf99b3e309d 100644 --- a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp +++ b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp @@ -179,7 +179,7 @@ int32_t ParseResourceDesc(const cJSON *json, CompConfig &cfg) return ERR_DH_FWK_JSON_PARSE_FAILED; } cJSON *resourceDescArray = cJSON_GetObjectItem(json, COMP_RESOURCE_DESC.c_str()); - cJSON *element; + cJSON *element = nullptr; cJSON_ArrayForEach(element, resourceDescArray) { ResourceDesc desc; if (!IsString(element, COMP_SUBTYPE)) { @@ -265,7 +265,7 @@ int32_t ComponentLoader::GetCompPathAndVersion(const std::string &jsonStr, std:: cJSON_Delete(root); return ERR_DH_FWK_PARA_INVALID; } - cJSON *component; + cJSON *component = nullptr; cJSON_ArrayForEach(component, components) { CompConfig config; ParseCompConfigFromJson(component, config); @@ -320,7 +320,7 @@ void ComponentLoader::ParseCompConfigFromJson(cJSON *component, CompConfig &conf void ComponentLoader::ParseResourceDescFromJson(cJSON *resourceDescs, CompConfig &config) { - cJSON *resourceDesc; + cJSON *resourceDesc = nullptr; cJSON_ArrayForEach(resourceDesc, resourceDescs) { bool sensitiveValue; cJSON *sensitive = cJSON_GetObjectItem(resourceDesc, COMP_SENSITIVE.c_str()); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 525268eb97bb786d0e11a57cfb2ed28a74ca1782..4345fd020f21107d86f76113bf595fd047234446 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -67,7 +67,8 @@ namespace { } ComponentManager::ComponentManager() : compSource_({}), compSink_({}), compSrcSaId_({}), - compMonitorPtr_(std::make_shared()), lowLatencyListener_(new(std::nothrow) LowLatencyListener), + compMonitorPtr_(std::make_shared()), + lowLatencyListener_(sptr(new(std::nothrow) LowLatencyListener())), isUnInitTimeOut_(false), dhBizStates_({}), dhStateListener_(std::make_shared()), dataSyncTriggerListener_(std::make_shared()), dhCommToolPtr_(std::make_shared()), needRefreshTaskParams_({}) diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp index 6871330b24d961261e6eff707748fec34abc040c..8c5bab270e1baa2bcd586383294a2c25c9341b86 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp @@ -120,7 +120,7 @@ void FromJson(const cJSON *jsonObject, VersionInfo &versionInfo) const cJSON *compVer = cJSON_GetObjectItem(jsonObject, COMP_VER.c_str()); if (compVer != NULL) { - cJSON *compVerObj; + cJSON *compVerObj = nullptr; cJSON_ArrayForEach(compVerObj, compVer) { CompVersion compVerValue; FromJson(compVerObj, compVerValue); diff --git a/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp b/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp index 3998af7e699aa331e46eb742d73ded3c0d3266dd..29e89855936d28059df182077a44da1756faddf3 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp @@ -108,6 +108,10 @@ void DHCommTool::GetAndSendLocalFullCaps(const std::string &reqNetworkId) capsRsp.networkId = GetLocalNetworkId(); capsRsp.caps = resInfos; cJSON *root = cJSON_CreateObject(); + if (root == nullptr) { + DHLOGE("Create cJSON object failed."); + return; + } ToJson(root, capsRsp); char *msg = cJSON_PrintUnformatted(root); if (msg == nullptr) { diff --git a/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp b/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp index feebd097b9c02795e51f888b84936385edfdcfb6..151070c7301d10beeea90040f92ea8c7253a14d7 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp @@ -16,6 +16,7 @@ #include "dh_transport_obj.h" #include "dh_utils_tool.h" +#include "distributed_hardware_log.h" namespace OHOS { namespace DistributedHardware { @@ -81,6 +82,10 @@ void FromJson(const cJSON *jsonObject, CommMsg &commMsg) std::string GetCommMsgString(const CommMsg &commMsg) { cJSON *rootMsg = cJSON_CreateObject(); + if (rootMsg == nullptr) { + DHLOGE("Create cJSON object failed."); + return ""; + } ToJson(rootMsg, commMsg); char *msg = cJSON_PrintUnformatted(rootMsg); if (msg == nullptr) { diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentloader/src/component_loader_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentloader/src/component_loader_test.cpp index d51654fc3cbd6839538d3282c0d20101f1b486c5..075d44030d5f6d0f20a161ab1daf77d6c54daa4f 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentloader/src/component_loader_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentloader/src/component_loader_test.cpp @@ -292,11 +292,22 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_018, TestSize.Level0) const char *TYPE = "TYPE"; const char *PATH = "PATH"; cJSON* json0bject = cJSON_CreateObject(); + if (json0bject == nullptr) { + return; + } cJSON* compVers = cJSON_CreateObject(); + if (compVers == nullptr) { + cJSON_Delete(json0bject); + return; + } cJSON_AddStringToObject(compVers, NAME, "name"); cJSON_AddNumberToObject(compVers, TYPE, 1111); cJSON_AddItemToObject(json0bject, PATH, compVers); char* cjson = cJSON_PrintUnformatted(json0bject); + if (cjson == nullptr) { + cJSON_Delete(json0bject); + return; + } std::string jsonStr(cjson); std::map dhtypeMap; int32_t ret = ComponentLoader::GetInstance().GetCompPathAndVersion(jsonStr, dhtypeMap); @@ -439,6 +450,9 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_029, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddNumberToObject(json, COMP_NAME.c_str(), 4801); from_json(json, cfg); @@ -456,6 +470,9 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_030, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name"); cJSON_AddNumberToObject(json, COMP_TYPE.c_str(), 0x02); @@ -474,6 +491,9 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_031, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name"); cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO"); cJSON_AddNumberToObject(json, COMP_HANDLER_LOC.c_str(), 4801); @@ -493,6 +513,9 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_032, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name"); cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO"); cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc"); @@ -513,6 +536,9 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_033, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name"); cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO"); cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc"); @@ -534,6 +560,9 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_034, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name"); cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO"); cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc"); @@ -556,6 +585,9 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_035, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name"); cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO"); cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc"); @@ -579,6 +611,9 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_036, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name"); cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO"); cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc"); @@ -603,6 +638,9 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_037, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name"); cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO"); cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc"); @@ -628,6 +666,9 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_038, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name"); cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO"); cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc"); @@ -654,6 +695,9 @@ HWTEST_F(ComponentLoaderTest, component_loader_test_039, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "name"); cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "DHType::AUDIO"); cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc"); @@ -674,6 +718,9 @@ HWTEST_F(ComponentLoaderTest, ParseSink_001, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddNumberToObject(json, COMP_SINK_LOC.c_str(), 100); auto ret = ParseSink(json, cfg); cJSON_Delete(json); @@ -684,6 +731,9 @@ HWTEST_F(ComponentLoaderTest, ParseSink_002, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_SINK_LOC.c_str(), "comp_sink_loc_test"); cJSON_AddNumberToObject(json, COMP_SINK_VERSION.c_str(), 100); auto ret = ParseSink(json, cfg); @@ -695,6 +745,9 @@ HWTEST_F(ComponentLoaderTest, ParseSink_003, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_SINK_LOC.c_str(), "comp_sink_loc_test"); cJSON_AddStringToObject(json, COMP_SINK_VERSION.c_str(), "1.0"); cJSON_AddStringToObject(json, COMP_SINK_SA_ID.c_str(), "comp_sink_sa_id_test"); @@ -707,6 +760,9 @@ HWTEST_F(ComponentLoaderTest, ParseSink_004, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_SINK_LOC.c_str(), "comp_sink_loc_test"); cJSON_AddStringToObject(json, COMP_SINK_VERSION.c_str(), "1.0"); cJSON_AddNumberToObject(json, COMP_SINK_SA_ID.c_str(), 4801); @@ -719,17 +775,31 @@ HWTEST_F(ComponentLoaderTest, ParseResourceDesc_001, TestSize.Level0) { CompConfig cfg; cJSON *array = cJSON_CreateArray(); + if (array == nullptr) { + return; + } cJSON *obj = cJSON_CreateObject(); + if (obj == nullptr) { + cJSON_Delete(array); + return; + } cJSON_AddStringToObject(obj, COMP_SUBTYPE.c_str(), "comp_subtype"); cJSON_AddBoolToObject(obj, COMP_SENSITIVE.c_str(), true); cJSON_AddItemToArray(array, obj); cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + cJSON_Delete(array); + return; + } cJSON_AddItemToObject(json, COMP_RESOURCE_DESC.c_str(), array); auto ret = ParseResourceDesc(json, cfg); cJSON_Delete(json); CompConfig config; cJSON *component = cJSON_CreateObject(); + if (component == nullptr) { + return; + } cJSON_AddNumberToObject(component, COMP_NAME.c_str(), 1); cJSON_AddNumberToObject(component, COMP_TYPE.c_str(), 1); cJSON_AddNumberToObject(component, COMP_HANDLER_LOC.c_str(), 1); @@ -744,9 +814,25 @@ HWTEST_F(ComponentLoaderTest, ParseResourceDesc_001, TestSize.Level0) ComponentLoader::GetInstance().ParseCompConfigFromJson(component, config); cJSON_Delete(component); EXPECT_EQ(ret, DH_FWK_SUCCESS); +} + +HWTEST_F(ComponentLoaderTest, ParseResourceDesc_002, TestSize.Level0) +{ + CompConfig cfg; + cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } + cJSON_AddNumberToObject(json, COMP_NAME.c_str(), 100); + auto ret = ParseComponent(json, cfg); + cJSON_Delete(json); + EXPECT_EQ(ret, ERR_DH_FWK_JSON_PARSE_FAILED); CompConfig config1; cJSON *component1 = cJSON_CreateObject(); + if (component1 == nullptr) { + return; + } cJSON_AddStringToObject(component1, COMP_NAME.c_str(), "comp_name_test"); cJSON_AddStringToObject(component1, COMP_TYPE.c_str(), "comp_type_test"); cJSON_AddStringToObject(component1, COMP_HANDLER_LOC.c_str(), "comp_handler_loc_test"); @@ -759,7 +845,6 @@ HWTEST_F(ComponentLoaderTest, ParseResourceDesc_001, TestSize.Level0) cJSON_AddNumberToObject(component1, COMP_SINK_SA_ID.c_str(), 4802); cJSON_AddStringToObject(component1, COMP_RESOURCE_DESC.c_str(), "comp_resource_desc"); ComponentLoader::GetInstance().ParseCompConfigFromJson(component1, config1); - EXPECT_EQ(ret, DH_FWK_SUCCESS); cJSON_Delete(component1); } @@ -767,11 +852,17 @@ HWTEST_F(ComponentLoaderTest, from_json_001, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddNumberToObject(json, COMP_NAME.c_str(), 100); from_json(json, cfg); cJSON_Delete(json); cJSON *Json1 = cJSON_CreateObject(); + if (Json1 == nullptr) { + return; + } cJSON_AddStringToObject(Json1, COMP_NAME.c_str(), "comp_name_test"); cJSON_AddStringToObject(Json1, COMP_TYPE.c_str(), "comp_type_test"); cJSON_AddStringToObject(Json1, COMP_HANDLER_LOC.c_str(), "comp_handler_loc_test"); @@ -781,6 +872,9 @@ HWTEST_F(ComponentLoaderTest, from_json_001, TestSize.Level0) cJSON_Delete(Json1); cJSON *Json2 = cJSON_CreateObject(); + if (Json2 == nullptr) { + return; + } cJSON_AddStringToObject(Json2, COMP_NAME.c_str(), "comp_name_test"); cJSON_AddStringToObject(Json2, COMP_TYPE.c_str(), "comp_type_test"); cJSON_AddStringToObject(Json2, COMP_HANDLER_LOC.c_str(), "comp_handler_loc_test"); @@ -798,6 +892,9 @@ HWTEST_F(ComponentLoaderTest, ParseComponent_001, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddNumberToObject(json, COMP_NAME.c_str(), 100); auto ret = ParseComponent(json, cfg); cJSON_Delete(json); @@ -808,6 +905,9 @@ HWTEST_F(ComponentLoaderTest, ParseComponent_002, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "comp_name_test"); cJSON_AddNumberToObject(json, COMP_TYPE.c_str(), 100); auto ret = ParseComponent(json, cfg); @@ -819,6 +919,9 @@ HWTEST_F(ComponentLoaderTest, ParseComponent_003, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "comp_name_test"); cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "comp_type_test"); cJSON_AddNumberToObject(json, COMP_HANDLER_LOC.c_str(), 100); @@ -831,6 +934,9 @@ HWTEST_F(ComponentLoaderTest, ParseComponent_004, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "comp_name_test"); cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "comp_type_test"); cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc_test"); @@ -844,6 +950,9 @@ HWTEST_F(ComponentLoaderTest, ParseComponent_005, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_NAME.c_str(), "comp_name_test"); cJSON_AddStringToObject(json, COMP_TYPE.c_str(), "comp_type_test"); cJSON_AddStringToObject(json, COMP_HANDLER_LOC.c_str(), "comp_handler_loc_test"); @@ -857,6 +966,9 @@ HWTEST_F(ComponentLoaderTest, ParseSource_001, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddNumberToObject(json, COMP_SOURCE_LOC.c_str(), 100); auto ret = ParseSource(json, cfg); cJSON_Delete(json); @@ -867,6 +979,9 @@ HWTEST_F(ComponentLoaderTest, ParseSource_002, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_SOURCE_LOC.c_str(), "comp_source_loc_test"); cJSON_AddNumberToObject(json, COMP_SOURCE_VERSION.c_str(), 100); auto ret = ParseSource(json, cfg); @@ -878,6 +993,9 @@ HWTEST_F(ComponentLoaderTest, ParseSource_003, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_SOURCE_LOC.c_str(), "comp_source_loc_test"); cJSON_AddStringToObject(json, COMP_SOURCE_VERSION.c_str(), "1.0"); cJSON_AddStringToObject(json, COMP_SOURCE_SA_ID.c_str(), "4801"); @@ -890,6 +1008,9 @@ HWTEST_F(ComponentLoaderTest, ParseSource_004, TestSize.Level0) { CompConfig cfg; cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, COMP_SOURCE_LOC.c_str(), "comp_source_loc_test"); cJSON_AddStringToObject(json, COMP_SOURCE_VERSION.c_str(), "1.0"); cJSON_AddNumberToObject(json, COMP_SOURCE_SA_ID.c_str(), 4801); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwareservice/src/distributed_hardware_service_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwareservice/src/distributed_hardware_service_test.cpp index 57f000e448dd1fe113bd7875886f3d3728ca4b67..c0e0a8b5b5bd73b03850bfcbb02073b5c8682890 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwareservice/src/distributed_hardware_service_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/distributedhardwareservice/src/distributed_hardware_service_test.cpp @@ -281,8 +281,15 @@ HWTEST_F(DistributedHardwareServiceTest, QueryDhSysSpec_002, TestSize.Level0) std::string targetKey = "histmAudEnc"; int32_t target = 100; cJSON *attrJson = cJSON_CreateObject(); + if (attrJson == nullptr) { + return; + } cJSON_AddNumberToObject(attrJson, targetKey.c_str(), target); char* cjson = cJSON_PrintUnformatted(attrJson); + if (cjson == nullptr) { + cJSON_Delete(attrJson); + return; + } std::string attrs(cjson); DistributedHardwareService service(ASID, true); auto ret = service.QueryDhSysSpec(targetKey, attrs); @@ -291,9 +298,16 @@ HWTEST_F(DistributedHardwareServiceTest, QueryDhSysSpec_002, TestSize.Level0) cJSON_Delete(attrJson); cJSON *attrJson1 = cJSON_CreateObject(); + if (attrJson1 == nullptr) { + return; + } std::string targetKeyValue = "targetKeyValue"; cJSON_AddStringToObject(attrJson1, targetKey.c_str(), targetKeyValue.c_str()); char* cjson1 = cJSON_PrintUnformatted(attrJson1); + if (cjson1 == nullptr) { + cJSON_Delete(attrJson1); + return; + } std::string attrs1(cjson1); ret = service.QueryDhSysSpec(targetKey, attrs1); EXPECT_NE(0, ret.length()); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp index d790496b03794f1fc9f5f1d50629892acb1b0f0c..31ccec6f9d607d26daaf26b56261c58381cd6355 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/lowlatency/lowlatencylistener/src/low_latency_listener_test.cpp @@ -91,12 +91,19 @@ HWTEST_F(LowLatencyListenerTest, OnMessage_004, TestSize.Level0) DHTopic topic = DHTopic::TOPIC_START_DSCREEN; cJSON* json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } const char* DH_TYPE = "dh_type"; const char* LOW_LATENCY_ENABLE = "low_latency_enable"; cJSON_AddStringToObject(json, DH_TYPE, "dh_type"); cJSON_AddStringToObject(json, LOW_LATENCY_ENABLE, "low_latency_enable"); char* cjson = cJSON_PrintUnformatted(json); + if (cjson == nullptr) { + cJSON_Delete(json); + return; + } std::string message(cjson); listener_->OnMessage(topic, message); cJSON_free(cjson); @@ -130,11 +137,18 @@ HWTEST_F(LowLatencyListenerTest, OnMessage_006, TestSize.Level0) { DHTopic topic = DHTopic::TOPIC_START_DSCREEN; cJSON* json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } const char* DH_TYPE = "dh_type"; const char* LOW_LATENCY_ENABLE = "low_latency_enable"; cJSON_AddNumberToObject(json, DH_TYPE, 0x01); cJSON_AddBoolToObject(json, LOW_LATENCY_ENABLE, true); char* cjson = cJSON_PrintUnformatted(json); + if (cjson == nullptr) { + cJSON_Delete(json); + return; + } std::string message(cjson); listener_->OnMessage(topic, message); cJSON_free(cjson); @@ -152,11 +166,18 @@ HWTEST_F(LowLatencyListenerTest, OnMessage_007, TestSize.Level0) { DHTopic topic = DHTopic::TOPIC_START_DSCREEN; cJSON* json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } const char* DH_TYPE = "dh_type"; const char* LOW_LATENCY_ENABLE = "low_latency_enable"; cJSON_AddNumberToObject(json, DH_TYPE, 0x01); cJSON_AddBoolToObject(json, LOW_LATENCY_ENABLE, false); char* cjson = cJSON_PrintUnformatted(json); + if (cjson == nullptr) { + cJSON_Delete(json); + return; + } std::string message(cjson); listener_->OnMessage(topic, message); cJSON_free(cjson); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp index 7d842a730291df3e03c97d5994c41edb4bdf3c3e..50b34de903d77150bb30d4b1f7e97f502da60e5b 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp @@ -847,6 +847,9 @@ HWTEST_F(ResourceManagerTest, FromJson_001, TestSize.Level0) CapabilityInfo info(dhId, devId, devName, devType, dhType, dhAttrs, dhSubtype); cJSON* json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } const char* DH_ID = "dh_id"; const char* DEV_ID = "dev_id"; const char* DEV_NAME = "dev_name"; @@ -864,6 +867,10 @@ HWTEST_F(ResourceManagerTest, FromJson_001, TestSize.Level0) cJSON_AddStringToObject(json, DH_SUBTYPE, "dh_subtype"); char* cjson = cJSON_PrintUnformatted(json); + if (cjson == nullptr) { + cJSON_Delete(json); + return; + } std::string jsonStr(cjson); cJSON_free(cjson); cJSON_Delete(json); @@ -1128,6 +1135,9 @@ HWTEST_F(ResourceManagerTest, FromJson_002, TestSize.Level0) std::string dhSubtype = "dhSubtype_test"; std::string sinkVersion = "sinkVersion_test"; cJSON *jsonObj = cJSON_CreateObject(); + if (jsonObj == nullptr) { + return; + } cJSON_AddStringToObject(jsonObj, DH_ID.c_str(), dhId.c_str()); cJSON_AddStringToObject(jsonObj, DEV_ID.c_str(), dveId.c_str()); cJSON_AddStringToObject(jsonObj, DEV_NAME.c_str(), devName.c_str()); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/versioninfo/src/version_info_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/versioninfo/src/version_info_test.cpp index 18b30c472375b9b95d11c7b221a0ee0f4214be59..a6f196d5abf3adbdcf389a2e94efc3a8bfdfd40a 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/versioninfo/src/version_info_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/versioninfo/src/version_info_test.cpp @@ -102,6 +102,9 @@ HWTEST_F(VersionInfoTest, FromJson_001, TestSize.Level0) const char* DH_ATTRS = "dh_attrs"; cJSON* json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, DH_ID, "dh_id"); cJSON_AddStringToObject(json, DEV_ID, "dev_id"); cJSON_AddStringToObject(json, DEV_NAME, "dev_name"); @@ -109,6 +112,10 @@ HWTEST_F(VersionInfoTest, FromJson_001, TestSize.Level0) cJSON_AddStringToObject(json, DH_TYPE, "dh_type"); cJSON_AddStringToObject(json, DH_ATTRS, "dh_attrs"); char* cjson = cJSON_PrintUnformatted(json); + if (cjson == nullptr) { + cJSON_Delete(json); + return; + } std::string jsonStr(cjson); cJSON_free(cjson); cJSON_Delete(json); @@ -131,6 +138,9 @@ HWTEST_F(VersionInfoTest, FromJson_002, TestSize.Level0) const char* DH_TYPE = "dh_type"; const char* DH_ATTRS = "dh_attrs"; cJSON* json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddStringToObject(json, DH_ID, "dh_id"); cJSON_AddStringToObject(json, DEV_ID, "dev_id"); cJSON_AddStringToObject(json, DEV_NAME, "dev_name"); @@ -138,6 +148,10 @@ HWTEST_F(VersionInfoTest, FromJson_002, TestSize.Level0) cJSON_AddStringToObject(json, DH_TYPE, "dh_type"); cJSON_AddStringToObject(json, DH_ATTRS, "dh_attrs"); char* cjson = cJSON_PrintUnformatted(json); + if (cjson == nullptr) { + cJSON_Delete(json); + return; + } std::string jsonStr(cjson); cJSON_free(cjson); cJSON_Delete(json); diff --git a/utils/src/histreamer_ability_parser.cpp b/utils/src/histreamer_ability_parser.cpp index a9631116a76b850bbb2400755838fc30416093e6..cb29ebe5a30475ce4920ccf5c864cda2d95cec0a 100644 --- a/utils/src/histreamer_ability_parser.cpp +++ b/utils/src/histreamer_ability_parser.cpp @@ -51,9 +51,9 @@ void FromJson(const cJSON *jsonObject, AudioEncoderIn &audioEncoderIn) DHLOGE("AudioEncoderIn SAMPLE_RATE is invalid\n"); return; } - cJSON *sampleRateItem; + cJSON *sampleRateItem = nullptr; cJSON_ArrayForEach(sampleRateItem, sampleRate) { - audioEncoderIn.sample_rate.push_back((uint32_t)sampleRateItem->valuedouble); + audioEncoderIn.sample_rate.push_back((uint32_t)sampleRateItem->valuedouble); } } @@ -98,11 +98,11 @@ void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder) return; } cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); - cJSON *inJson; + cJSON *inJson = nullptr; cJSON_ArrayForEach(inJson, insJson) { - AudioEncoderIn in; - FromJson(inJson, in); - audioEncoder.ins.push_back(in); + AudioEncoderIn in; + FromJson(inJson, in); + audioEncoder.ins.push_back(in); } if (!IsArray(jsonObject, OUTS)) { @@ -110,11 +110,11 @@ void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder) return; } cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); - cJSON *outJson; + cJSON *outJson = nullptr; cJSON_ArrayForEach(outJson, outsJson) { - AudioEncoderOut out; - FromJson(outJson, out); - audioEncoder.outs.push_back(out); + AudioEncoderOut out; + FromJson(outJson, out); + audioEncoder.outs.push_back(out); } } @@ -131,9 +131,9 @@ void FromJson(const cJSON *jsonObject, AudioDecoderIn &audioDecoderIn) return; } const cJSON *channelLayoutJson = cJSON_GetObjectItem(jsonObject, AUDIO_CHANNEL_LAYOUT.c_str()); - const cJSON *layout; + const cJSON *layout = nullptr; cJSON_ArrayForEach(layout, channelLayoutJson) { - audioDecoderIn.channel_layout.push_back((AudioChannelLayout)layout->valuedouble); + audioDecoderIn.channel_layout.push_back((AudioChannelLayout)layout->valuedouble); } } @@ -149,7 +149,7 @@ void FromJson(const cJSON *jsonObject, AudioDecoderOut &audioDecoderOut) return; } cJSON *sampleFormatJson = cJSON_GetObjectItem(jsonObject, AUDIO_SAMPLE_FORMAT.c_str()); - cJSON *format; + cJSON *format = nullptr; cJSON_ArrayForEach(format, sampleFormatJson) { audioDecoderOut.sample_fmt.push_back((AudioSampleFormat)format->valuedouble); } @@ -168,7 +168,7 @@ void FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder) return; } const cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); - cJSON *inJson; + cJSON *inJson = nullptr; cJSON_ArrayForEach(inJson, insJson) { AudioDecoderIn in; FromJson(inJson, in); @@ -179,7 +179,7 @@ void FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder) return; } cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); - cJSON *outJson; + cJSON *outJson = nullptr; cJSON_ArrayForEach(outJson, outsJson) { AudioDecoderOut out; FromJson(outJson, out); @@ -200,7 +200,7 @@ void FromJson(const cJSON *jsonObject, VideoEncoderIn &videoEncoderIn) return; } cJSON *videoPixelFmt = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str()); - cJSON *pixelFmt; + cJSON *pixelFmt = nullptr; cJSON_ArrayForEach(pixelFmt, videoPixelFmt) { videoEncoderIn.pixel_fmt.push_back((VideoPixelFormat)pixelFmt->valuedouble); } @@ -228,7 +228,7 @@ void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder) return; } cJSON *videoEncoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); - cJSON *inJson; + cJSON *inJson = nullptr; cJSON_ArrayForEach(inJson, videoEncoderInsJson) { VideoEncoderIn in; FromJson(inJson, in); @@ -240,7 +240,7 @@ void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder) return; } cJSON *videoEncoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); - cJSON *outJson; + cJSON *outJson = nullptr; cJSON_ArrayForEach(outJson, videoEncoderOutsJson) { VideoEncoderOut out; FromJson(outJson, out); @@ -261,7 +261,7 @@ void FromJson(const cJSON *jsonObject, VideoDecoderIn &videoDecoderIn) return; } cJSON *videoBitStreamFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_BIT_STREAM_FMT.c_str()); - cJSON *fmt; + cJSON *fmt = nullptr; cJSON_ArrayForEach(fmt, videoBitStreamFmtJson) { videoDecoderIn.vd_bit_stream_fmt.push_back((VideoBitStreamFormat)(fmt->valuedouble)); } @@ -280,7 +280,7 @@ void FromJson(const cJSON *jsonObject, VideoDecoderOut &videoDecoderOut) return; } cJSON *videoPixelFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str()); - cJSON *fmt; + cJSON *fmt = nullptr; cJSON_ArrayForEach(fmt, videoPixelFmtJson) { videoDecoderOut.pixel_fmt.push_back((VideoPixelFormat)(fmt->valuedouble)); } @@ -299,7 +299,7 @@ void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder) return; } cJSON *videoDecoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); - cJSON *inJson; + cJSON *inJson = nullptr; cJSON_ArrayForEach(inJson, videoDecoderInsJson) { VideoDecoderIn in; FromJson(inJson, in); @@ -311,7 +311,7 @@ void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder) return; } cJSON *videoDecoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); - cJSON *outJson; + cJSON *outJson = nullptr; cJSON_ArrayForEach(outJson, videoDecoderOutsJson) { VideoDecoderOut out; FromJson(outJson, out); diff --git a/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp b/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp index fb64b6666d1a532a4c7403bdf2e9f8e12d0dfa89..f5077e236df0b4264d87527317507ee8be9f2c63 100644 --- a/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp +++ b/utils/test/unittest/common/histreamer_ability_parser/histreamer_ability_parser_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -70,6 +70,9 @@ void HistreamerAbilityParserTest::TearDown() {} HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_001, TestSize.Level0) { cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddNumberToObject(json, MIME.c_str(), (double)(UINT16_ONE)); AudioEncoderIn audioEncoderIn; FromJson(json, audioEncoderIn); @@ -86,6 +89,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_001, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_002, TestSize.Level0) { cJSON *json = cJSON_CreateObject(); + if (json == nullptr) { + return; + } cJSON_AddNumberToObject(json, MIME.c_str(), (double)(UINT16_ONE)); AudioEncoderOut audioEncoderOut; FromJson(json, audioEncoderOut); @@ -117,6 +123,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_002, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_003, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } cJSON_AddNumberToObject(jsonObject, NAME.c_str(), (double)(UINT16_ONE)); AudioEncoder audioEncoder; FromJson(jsonObject, audioEncoder); @@ -146,6 +155,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_003, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_004, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } AudioDecoderIn audioDecoderIn; cJSON_AddNumberToObject(jsonObject, MIME.c_str(), (double)(UINT16_ONE)); FromJson(jsonObject, audioDecoderIn); @@ -167,6 +179,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_004, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_005, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } AudioDecoderOut audioDecoderOut; cJSON_AddNumberToObject(jsonObject, MIME.c_str(), (double)(UINT16_ONE)); FromJson(jsonObject, audioDecoderOut); @@ -188,6 +203,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_005, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_006, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } AudioDecoder audioDecoder; cJSON_AddNumberToObject(jsonObject, NAME.c_str(), (double)(UINT16_ONE)); FromJson(jsonObject, audioDecoder); @@ -221,6 +239,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_006, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_007, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } VideoEncoderIn videoEncoderIn; cJSON_AddNumberToObject(jsonObject, MIME.c_str(), (double)(UINT16_ONE)); FromJson(jsonObject, videoEncoderIn); @@ -242,6 +263,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_007, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_008, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } VideoEncoderOut videoEncoderOut; cJSON_AddNumberToObject(jsonObject, MIME.c_str(), (double)(UINT16_ONE)); FromJson(jsonObject, videoEncoderOut); @@ -258,6 +282,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_008, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_009, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } VideoEncoder videoEncoder; cJSON_AddNumberToObject(jsonObject, NAME.c_str(), (double)(UINT16_ONE)); FromJson(jsonObject, videoEncoder); @@ -291,6 +318,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_009, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_010, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } VideoDecoderIn videoDecoderIn; cJSON_AddNumberToObject(jsonObject, MIME.c_str(), (double)(UINT16_ONE)); FromJson(jsonObject, videoDecoderIn); @@ -312,6 +342,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_010, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_011, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } VideoDecoderOut videoDecoderOut; cJSON_AddNumberToObject(jsonObject, MIME.c_str(), (double)(UINT16_ONE)); FromJson(jsonObject, videoDecoderOut); @@ -333,6 +366,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_011, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_012, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } VideoDecoder videoDecoder; cJSON_AddNumberToObject(jsonObject, NAME.c_str(), (double)(UINT16_ONE)); FromJson(jsonObject, videoDecoder); @@ -365,6 +401,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_012, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_013, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } AudioEncoder audioEncoder; cJSON_AddStringToObject(jsonObject, NAME.c_str(), AUDIO_ENCODER_NAME.c_str()); audioEncoder.name = AUDIO_ENCODER_NAME; @@ -387,6 +426,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_013, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_014, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } AudioDecoder audioDecoder; cJSON_AddStringToObject(jsonObject, NAME.c_str(), AUDIO_DECODER_NAME.c_str()); audioDecoder.name = AUDIO_DECODER_NAME; @@ -409,6 +451,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_014, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_015, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } VideoEncoder videoEncoder; cJSON_AddStringToObject(jsonObject, NAME.c_str(), VIDEO_ENCODER_NAME.c_str()); videoEncoder.name = VIDEO_ENCODER_NAME; @@ -431,6 +476,9 @@ HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_015, TestSi HWTEST_F(HistreamerAbilityParserTest, histreamer_ability_parser_test_016, TestSize.Level0) { cJSON *jsonObject = cJSON_CreateObject(); + if (jsonObject == nullptr) { + return; + } VideoDecoder videoDecoder; cJSON_AddStringToObject(jsonObject, NAME.c_str(), VIDEO_DECODER_NAME.c_str()); videoDecoder.name = VIDEO_DECODER_NAME;