From: Youngjae Cho Date: Wed, 13 Dec 2023 04:55:41 +0000 (+0900) Subject: halapi: Fix strncpy() warnings X-Git-Tag: accepted/tizen/unified/20240116.155507~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04463c058f1f2c1169bb25c9e455d1b680f3bb6d;p=platform%2Fhal%2Fapi%2Fcommon.git halapi: Fix strncpy() warnings Those strncpy() cause warnings, -Wstringop-truncate, -Wstringop-overflow due to the length calculated by strlen(). Replace the length with the explicit size specified by the parameter. It is logically the same as before. Change-Id: I5b06f8595aa89f32fc7a6becab31130eb1178116 Signed-off-by: Youngjae Cho --- diff --git a/src/hal-api-common.c b/src/hal-api-common.c index 3520a58..8d63818 100644 --- a/src/hal-api-common.c +++ b/src/hal-api-common.c @@ -80,8 +80,7 @@ int hal_common_get_backend_library_name(enum hal_module module, char *name, int name = NULL; goto out; } - strncpy(name, library_name, len_library_name); - name[len_library_name] = '\0'; + strncpy(name, library_name, size); ret = 0; out: @@ -136,8 +135,7 @@ static int __hal_common_get_backend_name(enum hal_module module, char *name, int str = NULL; goto out; } - strncpy(name, str, len_str); - name[len_str] = '\0'; + strncpy(name, str, size); ret = 0; out: @@ -458,8 +456,7 @@ static int __get_backend_data(enum hal_module module, unsigned int *abi_version, goto err_conf_exit; } - strncpy(name, info->backend->name, len); - name[len] = '\0'; + strncpy(name, info->backend->name, name_size); /* Return vendor of hal_backend structure */ } else if (info->backend->vendor && !name_size && vendor_size) { @@ -471,8 +468,7 @@ static int __get_backend_data(enum hal_module module, unsigned int *abi_version, goto err_conf_exit; } - strncpy(vendor, info->backend->vendor, len); - vendor[len] = '\0'; + strncpy(vendor, info->backend->vendor, vendor_size); } else { _E("%s: Failed to get backend data\n", info->module_name); ret = -EINVAL; @@ -641,7 +637,7 @@ static int __get_backend_library_data(enum hal_module module, struct dirent *de; DIR *dir; char *backend_module_name = NULL; - int count, i, ret, len; + int count, i, ret; #if defined(__aarch64__) || defined(__x86_64__) || defined (__riscv) const char hal_backend_path[] = "/hal/lib64"; #else @@ -696,12 +692,8 @@ static int __get_backend_library_data(enum hal_module module, if (lib_count == 0) count++; else if (lib_count > 0) { - len = strlen(de->d_name) + 1; - - if (len > lib_name_size) - len = lib_name_size; - - strncpy(lib_names[count++], de->d_name, len); + strncpy(lib_names[count], de->d_name, lib_name_size); + count++; } }