From f0a5bb7310d09314eb35fd3f52bc78ec6ae19a31 Mon Sep 17 00:00:00 2001 From: Jaehyun Kim Date: Wed, 1 Apr 2020 19:34:05 +0900 Subject: [PATCH] Fixed some array sizes to reduce unnecessary memory usage Some arrays are using more memory size than is actually needed. For this reason, the size of the arrays has been modified to reduce unnecessary memory usage. Change-Id: I6b74e6d201bd93b67deb1334385d2c281db0fc5b Signed-off-by: Jaehyun Kim --- include/network_config.h | 2 +- include/network_wlan.h | 4 ++-- src/network_dbus.c | 10 +++++----- src/network_interface.c | 14 +++++++------- src/network_signal.c | 2 +- src/wifi_ap.c | 2 +- src/wifi_internal.c | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/network_config.h b/include/network_config.h index 3e44b07..5fa53e2 100755 --- a/include/network_config.h +++ b/include/network_config.h @@ -25,7 +25,7 @@ extern "C" { #endif /* __cplusplus */ -#define NET_PROFILE_NAME_LEN_MAX 512 /** Profile name max length */ +#define NET_PROFILE_NAME_LEN_MAX 144 /** Profile name max length */ #define NET_HOME_URL_LEN_MAX 512 /** Home URL max length in profile account */ #define NET_IPV4_STR_LEN_MAX 15 /** Maximum length of IPv4 string type e.g., "165.213.173.105". This length does not diff --git a/include/network_wlan.h b/include/network_wlan.h index 5f8df63..a95e77a 100755 --- a/include/network_wlan.h +++ b/include/network_wlan.h @@ -28,8 +28,8 @@ extern "C" { /** Length of raw SSID */ #define NET_WLAN_RAW_SSID_LEN 32 -/** Length of ESSID */ -#define NET_WLAN_ESSID_LEN 128 +/** Length of ESSID: 32(raw essid size) x 3(U+FFFD REPLACEMENT CHARACTER) */ +#define NET_WLAN_ESSID_LEN 96 /** Length of BSSID */ #define NET_WLAN_BSSID_LEN 17 diff --git a/src/network_dbus.c b/src/network_dbus.c index 5738bff..d4b52a8 100755 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -2013,7 +2013,7 @@ int _net_dbus_netlink_scan_request(GSList *nl_scan_list, const char *vsie) GSList *list = NULL; GVariant *params = NULL; GVariantBuilder *builder; - char ssid[NET_WLAN_ESSID_LEN] = {0, }; + char ssid[NET_WLAN_ESSID_LEN + 1] = {0, }; WIFI_LOG(WIFI_INFO, "Number of elements in a list: %d", g_slist_length(nl_scan_list)); @@ -2022,7 +2022,7 @@ int _net_dbus_netlink_scan_request(GSList *nl_scan_list, const char *vsie) if (nl_scan_list != NULL) { for (list = nl_scan_list; list; list = list->next) { WIFI_LOG(WIFI_INFO, "AP name: %s", (char *)list->data); - g_strlcpy(ssid, (char *)list->data, NET_WLAN_ESSID_LEN); + g_strlcpy(ssid, (char *)list->data, NET_WLAN_ESSID_LEN + 1); g_variant_builder_add(builder, "{sv}", "SSID", g_variant_new_string(ssid)); } } @@ -3749,7 +3749,7 @@ int _net_dbus_multi_scan_request(GSList *multi_scan_list) GSList *list = NULL; GVariant *params = NULL; GVariantBuilder *builder; - char ssid[NET_WLAN_ESSID_LEN] = {0, }; + char ssid[NET_WLAN_ESSID_LEN + 1] = {0, }; char freq[NET_WLAN_FREQ_LEN] = {0, }; WIFI_LOG(WIFI_INFO, "multi_scan_type:%d, Number of elements in a list:%d", @@ -3761,7 +3761,7 @@ int _net_dbus_multi_scan_request(GSList *multi_scan_list) if (request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].multi_scan_type == WIFI_MULTI_SCAN_SSID) { for (list = multi_scan_list; list; list = list->next) { WIFI_LOG(WIFI_INFO, "AP name: %s", ((wifi_manager_multi_scan_ap_s *)list->data)->str); - g_strlcpy(ssid, ((wifi_manager_multi_scan_ap_s *)list->data)->str, NET_WLAN_ESSID_LEN); + g_strlcpy(ssid, ((wifi_manager_multi_scan_ap_s *)list->data)->str, NET_WLAN_ESSID_LEN + 1); g_variant_builder_add(builder, "{sv}", "SSID", g_variant_new_string(ssid)); } } else if (request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].multi_scan_type == WIFI_MULTI_SCAN_FREQ) { @@ -3774,7 +3774,7 @@ int _net_dbus_multi_scan_request(GSList *multi_scan_list) for (list = multi_scan_list; list; list = list->next) { if (((wifi_manager_multi_scan_ap_s *)list->data)->flag == true) { WIFI_LOG(WIFI_INFO, "[Mixed]AP name: %s", ((wifi_manager_multi_scan_ap_s *)list->data)->str); - g_strlcpy(ssid, ((wifi_manager_multi_scan_ap_s *)list->data)->str, NET_WLAN_ESSID_LEN); + g_strlcpy(ssid, ((wifi_manager_multi_scan_ap_s *)list->data)->str, NET_WLAN_ESSID_LEN + 1); g_variant_builder_add(builder, "{sv}", "SSID_Mixed", g_variant_new_string(ssid)); } else { WIFI_LOG(WIFI_INFO, "[Mixed]Freq: %s", ((wifi_manager_multi_scan_ap_s *)list->data)->str); diff --git a/src/network_interface.c b/src/network_interface.c index 61d5bc4..3e813d2 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -902,7 +902,7 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* Prof value = g_variant_get_string(var, NULL); if (value != NULL) - g_strlcpy(ProfInfo->essid, value, NET_WLAN_ESSID_LEN); + g_strlcpy(ProfInfo->essid, value, NET_WLAN_ESSID_LEN + 1); } else if (g_strcmp0(key, "Passphrase") == 0) { wlan_security_info_s *security_info = &(ProfInfo->security_info); value = g_variant_get_string(var, NULL); @@ -1106,9 +1106,9 @@ static int __net_extract_service_info( return Error; } - g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX); + g_strlcpy(ProfInfo->ProfileName, ProfileName, NET_PROFILE_NAME_LEN_MAX + 1); g_strlcpy(ProfInfo->net_info.ProfileName, - ProfileName, NET_PROFILE_NAME_LEN_MAX); + ProfileName, NET_PROFILE_NAME_LEN_MAX + 1); Error = __net_extract_wifi_info(iter, ProfInfo); } @@ -1151,10 +1151,10 @@ static int __net_extract_all_services(GVariantIter *array, if (g_strrstr(obj + strlen(service_prefix), "hidden") != NULL) ProfInfo->is_hidden = TRUE; - g_strlcpy(ProfInfo->ProfileName, obj, NET_PROFILE_NAME_LEN_MAX); + g_strlcpy(ProfInfo->ProfileName, obj, NET_PROFILE_NAME_LEN_MAX + 1); g_strlcpy(ProfInfo->net_info.ProfileName, - obj, NET_PROFILE_NAME_LEN_MAX); + obj, NET_PROFILE_NAME_LEN_MAX + 1); Error = __net_extract_wifi_info(next, ProfInfo); @@ -1491,7 +1491,7 @@ int net_specific_scan_wifi(const char *ssid) } request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].flag = TRUE; - g_strlcpy(request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].ssid, ssid, NET_WLAN_ESSID_LEN+1); + g_strlcpy(request_table[NETWORK_REQUEST_TYPE_SPECIFIC_SCAN].ssid, ssid, NET_WLAN_ESSID_LEN + 1); Error = _net_dbus_specific_scan_request(ssid); if (Error != NET_ERR_NONE) { @@ -1639,7 +1639,7 @@ int net_multi_scan_wifi(GSList *multi_scan_list, gboolean multi_scan_type[]) WIFI_LOG(WIFI_ERROR, "Failed to allocate memory"); //LCOV_EXCL_LINE return NET_ERR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } - g_strlcpy(temp->str, ((wifi_manager_multi_scan_ap_s *)list->data)->str, NET_WLAN_ESSID_LEN); + g_strlcpy(temp->str, ((wifi_manager_multi_scan_ap_s *)list->data)->str, NET_WLAN_ESSID_LEN + 1); temp->flag = ((wifi_manager_multi_scan_ap_s *)list->data)->flag; request_table[NETWORK_REQUEST_TYPE_MULTI_SCAN].multi_scan_list = g_slist_append( diff --git a/src/network_signal.c b/src/network_signal.c index 5c2670e..86b8182 100755 --- a/src/network_signal.c +++ b/src/network_signal.c @@ -268,7 +268,7 @@ static int __net_handle_wifi_specific_scan_rsp(GVariant *param) return NET_ERR_UNKNOWN; } - g_strlcpy(bss->ssid, ssid, NET_WLAN_ESSID_LEN); + g_strlcpy(bss->ssid, ssid, NET_WLAN_ESSID_LEN + 1); if (raw_ssid != NULL && raw_ssid_len > 0 && raw_ssid_len < (NET_WLAN_RAW_SSID_LEN+1)) { memcpy(bss->raw_ssid, raw_ssid, raw_ssid_len); diff --git a/src/wifi_ap.c b/src/wifi_ap.c index 0a607e7..c4b7276 100755 --- a/src/wifi_ap.c +++ b/src/wifi_ap.c @@ -236,7 +236,7 @@ static bool _wifi_set_profile_name_to_ap(net_profile_info_s *ap_info) } g_strlcpy(ap_info->net_info.ProfileName, - profile_name, NET_PROFILE_NAME_LEN_MAX); + profile_name, NET_PROFILE_NAME_LEN_MAX + 1); g_free(profile_name); diff --git a/src/wifi_internal.c b/src/wifi_internal.c index 6fc9379..e32322a 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -3755,7 +3755,7 @@ int _wifi_specific_scan_set_ssid(wifi_manager_specific_scan_h specific_scan, WIFI_LOG(WIFI_ERROR, "Failed to allocate memory"); //LCOV_EXCL_LINE return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } - g_strlcpy(ap->str, essid, NET_WLAN_ESSID_LEN); + g_strlcpy(ap->str, essid, NET_WLAN_ESSID_LEN + 1); ap->flag = true; list = g_slist_append(list, ap); -- 2.7.4