From c9a67e1be77e07ec8cb01391d0704081e2160985 Mon Sep 17 00:00:00 2001 From: Dongju Chae Date: Tue, 11 Aug 2020 19:11:35 +0900 Subject: [PATCH] [Coverity] Resolve coverity issues due to uninitialized variables This patch resolves coverity issues due to uninitialized variables (UNINIT_CTOR, UNINIT). Signed-off-by: Dongju Chae --- src/core/utils/ne-conf.cc | 24 ++++++++++-------------- src/core/utils/ne-conf.h | 2 +- tests/apptests/dummy_triv2_internal.cc | 19 ++++++++++--------- tests/apptests/tvn_triv2_recurring.cc | 5 +++-- tests/unittests/ne_core_handler_test.cc | 6 ++++-- tests/unittests/ne_core_npu_test.cc | 2 +- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/core/utils/ne-conf.cc b/src/core/utils/ne-conf.cc index 3738735..e90a4ff 100644 --- a/src/core/utils/ne-conf.cc +++ b/src/core/utils/ne-conf.cc @@ -52,6 +52,15 @@ static int error_callback (const char*, ...) } /** + * @brief Constructor of Conf class, loading default configurations. + * @note this cannot be called explicitly. + */ +Conf::Conf () +{ + reset (); +} + +/** * @brief Load the configuration from .ini file and env-vars. * @param[in] inipath the path of .ini file (e.g., /etc/npu-engine.ini) * @detail Refer to the header file for more detail. @@ -67,8 +76,6 @@ Conf::loadConf (const char *inipath) /** Ignore error messages */ iniparser_set_error_callback (error_callback); - loadConfDefault(); - /** Load up config from ini if available */ dictionary *ini = iniparser_load (inipath != nullptr ? inipath : default_ini_path); if (ini) { @@ -81,20 +88,9 @@ Conf::loadConf (const char *inipath) } /** - * @brief load the default configuration + * @brief Restore configurations to the default ones */ void -Conf::loadConfDefault () -{ - static bool default_loaded = false; - - if (default_loaded) return; - - default_loaded = true; - reset (); -} - -void Conf::reset () { setResvMemSize (std::to_string (default_resv_mem_size).c_str()); diff --git a/src/core/utils/ne-conf.h b/src/core/utils/ne-conf.h index 792013e..bc8a29c 100644 --- a/src/core/utils/ne-conf.h +++ b/src/core/utils/ne-conf.h @@ -51,7 +51,7 @@ class Conf { static std::unique_ptr instance_; static std::once_flag once_flag_; - Conf () {} + Conf (); void loadConf (const char *inipath); void loadConfIni (dictionary *ini); diff --git a/tests/apptests/dummy_triv2_internal.cc b/tests/apptests/dummy_triv2_internal.cc index 23e6502..ed6f8dc 100644 --- a/tests/apptests/dummy_triv2_internal.cc +++ b/tests/apptests/dummy_triv2_internal.cc @@ -30,15 +30,11 @@ class TesterTRIV2 { public: TesterTRIV2 () : dev_ (nullptr), meta_ (nullptr), model_id_ (0) { - model_.size = 0; } ~TesterTRIV2 () { /** release resources */ if (dev_ != nullptr) { - if (model_.size > 0) - cleanNPU_modelBuffer (dev_, &model_); - if (model_id_ > 0) unregisterNPUmodel (dev_, model_id_); @@ -119,16 +115,21 @@ class TesterTRIV2 { meta_->output_seg_dims[0][2] = 1; meta_->output_seg_dims[0][3] = segment_size; - model_.type = BUFFER_MAPPED; - model_.size = meta_->size; - int status = allocNPU_modelBuffer (dev_, &model_); + generic_buffer model; + + model.type = BUFFER_MAPPED; + model.size = meta_->size; + int status = allocNPU_modelBuffer (dev_, &model); if (status != 0) return status; /** copy only metadata as it's dummy model */ - memcpy (model_.addr, meta_, NPUBIN_META_SIZE); + memcpy (model.addr, meta_, NPUBIN_META_SIZE); + + status = registerNPUmodel (dev_, &model, &model_id_); + cleanNPU_modelBuffer (dev_, &model); - return registerNPUmodel (dev_, &model_, &model_id_); + return status; } int set_data_info () { diff --git a/tests/apptests/tvn_triv2_recurring.cc b/tests/apptests/tvn_triv2_recurring.cc index 4c2b171..1fd5117 100644 --- a/tests/apptests/tvn_triv2_recurring.cc +++ b/tests/apptests/tvn_triv2_recurring.cc @@ -30,8 +30,9 @@ class ThirdPartyHW { public: ThirdPartyHW () { dev_ = nullptr; - input_.num_buffers = 0; - output_.num_buffers = 0; + + memset ((void *) &input_, '\x00', sizeof (input_)); + memset ((void *) &output_, '\x00', sizeof (output_)); } ~ThirdPartyHW () { diff --git a/tests/unittests/ne_core_handler_test.cc b/tests/unittests/ne_core_handler_test.cc index d6e8da7..b6aaf57 100644 --- a/tests/unittests/ne_core_handler_test.cc +++ b/tests/unittests/ne_core_handler_test.cc @@ -161,7 +161,8 @@ TEST (ne_core_handler_test, device_memory_args_n) static void create_model_buffer (generic_buffer & model_buf) { - npubin_meta meta; + npubin_meta meta = {0}; + meta.magiccode = NPUBIN_MAGICCODE | 0x1; /** npubinfmt v1 */ meta.buffer_size = 4096; meta.size = 4096; @@ -281,7 +282,8 @@ create_model_buffer_v2 (generic_buffer & model_buf) { uint32_t num_tensors = 4; - npubin_meta meta; + npubin_meta meta = {0}; + meta.magiccode = NPUBIN_MAGICCODE | 0x2; /** npubinfmt v2 */ meta.buffer_size = (uint64_t) 4096 * (uint64_t) num_tensors; meta.size = 4096; diff --git a/tests/unittests/ne_core_npu_test.cc b/tests/unittests/ne_core_npu_test.cc index 011a1d1..3435e0b 100644 --- a/tests/unittests/ne_core_npu_test.cc +++ b/tests/unittests/ne_core_npu_test.cc @@ -682,7 +682,7 @@ TEST (ne_core_npu_test, run_inference_async1_triv2) f_model = std::async(std::launch::async, [&] () -> model_config_t { int ret; - model_config_t model; + model_config_t model = {0}; /** register model data */ ret = api->alloc (size); -- 2.7.4