From 76f547e7633266c51a6e9c147da1658afa9e5b88 Mon Sep 17 00:00:00 2001 From: Daniel DeGrasse Date: Wed, 10 Jan 2024 12:17:53 -0600 Subject: [PATCH] net: l2: wifi: wifi_utils: Resolve build warning with strncpy function ARM GCC version 12.2.0 (Zephyr SDK 0.16.4) generates the following build warning from the strncpy call in "wifi_utils_parse_scan_bands": warning: '__builtin_strncpy' output truncated before terminating nul copying as many bytes from a string as its length To resolve this warning, pass the maximum length of the temporary parse_str buffer to strncpy. This also has the benefit of correctly null terminating parse_str, since we already verify the scan_bands_str is properly null terminated with the strlen() check in this function. We can therefore remove the line adding a null terminator to parse_str as well. Signed-off-by: Daniel DeGrasse --- subsys/net/l2/wifi/wifi_utils.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/subsys/net/l2/wifi/wifi_utils.c b/subsys/net/l2/wifi/wifi_utils.c index 79c858c5dd7..177e0d8ee02 100644 --- a/subsys/net/l2/wifi/wifi_utils.c +++ b/subsys/net/l2/wifi/wifi_utils.c @@ -241,8 +241,7 @@ int wifi_utils_parse_scan_bands(char *scan_bands_str, uint8_t *band_map) return -EINVAL; } - strncpy(parse_str, scan_bands_str, len); - parse_str[len] = '\0'; + strncpy(parse_str, scan_bands_str, sizeof(parse_str)); band_str = strtok_r(parse_str, ",", &ctx);