From e333b146648333ab11d0f42758b4925b6ca34f1a Mon Sep 17 00:00:00 2001 From: "Ruslan (The BadAss SysMan) Laishev" <ruslan.laishev@demlabs.net> Date: Fri, 11 Mar 2022 11:31:23 +0300 Subject: [PATCH] A portion of fixes in the dap_config_get_item_str() . Is related to incorrect der logik of handling of missing options in the config file. --- dap-sdk/core/src/dap_config.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/dap-sdk/core/src/dap_config.c b/dap-sdk/core/src/dap_config.c index 9064f362ca..25c45aedcc 100755 --- a/dap-sdk/core/src/dap_config.c +++ b/dap-sdk/core/src/dap_config.c @@ -532,9 +532,8 @@ static dap_config_item_t * dap_config_get_item(dap_config_t * a_config, const ch const char * dap_config_get_item_str(dap_config_t * a_config, const char * a_section_path, const char * a_item_name) { dap_config_item_t * item = dap_config_get_item(a_config, a_section_path, a_item_name); - if (item == NULL) - return NULL; - return item->data_str; + + return (!item) ? NULL : item->data_str; } @@ -595,15 +594,15 @@ const char * dap_config_get_item_str_default(dap_config_t * a_config, const char */ bool dap_config_get_item_bool(dap_config_t * a_config, const char * a_section_path, const char * a_item_name) { - const char *cp; +const char *l_str_ret; - if ( !(cp = dap_config_get_item_str(a_config, a_section_path, a_item_name)) ) + if ( !(l_str_ret = dap_config_get_item_str(a_config, a_section_path, a_item_name)) ) return false; #ifdef WIN32 return !strnicmp (cp, "true", 4); #else - return !strncasecmp (cp, "true", 4); /* 0 == True */ + return !strncasecmp (l_str_ret, "true", 4); /* 0 == True */ #endif } @@ -619,8 +618,12 @@ bool dap_config_get_item_bool(dap_config_t * a_config, const char * a_section_pa bool dap_config_get_item_bool_default(dap_config_t * a_config, const char * a_section_path, const char * a_item_name, bool a_default) { - return strcmp(dap_config_get_item_str_default(a_config,a_section_path,a_item_name, - a_default?"true":"false"),"true") == 0; +const char *l_str_ret; + + if ( !(l_str_ret = dap_config_get_item_str_default(a_config,a_section_path, a_item_name, a_default ? "true" : "false")) ) + return a_default; + + return !strcmp(l_str_ret, "true" ); } /** @@ -632,7 +635,10 @@ bool dap_config_get_item_bool_default(dap_config_t * a_config, const char * a_se */ double dap_config_get_item_double(dap_config_t * a_config, const char * a_section_path, const char * a_item_name) { - return atof(dap_config_get_item_str(a_config,a_section_path,a_item_name)); +const char *l_str_ret; + + l_str_ret = dap_config_get_item_str(a_config,a_section_path,a_item_name); + return l_str_ret ? atof(l_str_ret) : 0.0; } /** -- GitLab