2018-11-29 23:24:27

by An, Tedd

[permalink] [raw]
Subject: [PATCH] tools/btpclient: Fix compile warning with strncpy

This patch fixes the boundry warning-to-error in GCC 8.1.1 with strncpy.
---
tools/btpclient.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/btpclient.c b/tools/btpclient.c
index b217df58f..e77720ed1 100644
--- a/tools/btpclient.c
+++ b/tools/btpclient.c
@@ -376,8 +376,8 @@ static void btp_gap_read_info(uint8_t index, const void *param, uint16_t length,
goto failed;
}

- strncpy((char *) rp.name, str, sizeof(rp.name));
- strncpy((char *) rp.short_name, str, sizeof(rp.short_name));
+ snprintf((char *)rp.name, sizeof(rp.name), "%s", str);
+ snprintf((char *)rp.short_name, sizeof(rp.short_name), "%s", str);
rp.supported_settings = L_CPU_TO_LE32(adapter->supported_settings);
rp.current_settings = L_CPU_TO_LE32(adapter->current_settings);

--
2.17.2



2018-12-04 20:06:30

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH] tools/btpclient: Fix compile warning with strncpy

Hi Tedd,
On Fri, Nov 30, 2018 at 1:26 AM Tedd Ho-Jeong An <[email protected]> wrote:
>
> This patch fixes the boundry warning-to-error in GCC 8.1.1 with strncpy.
> ---
> tools/btpclient.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/btpclient.c b/tools/btpclient.c
> index b217df58f..e77720ed1 100644
> --- a/tools/btpclient.c
> +++ b/tools/btpclient.c
> @@ -376,8 +376,8 @@ static void btp_gap_read_info(uint8_t index, const void *param, uint16_t length,
> goto failed;
> }
>
> - strncpy((char *) rp.name, str, sizeof(rp.name));
> - strncpy((char *) rp.short_name, str, sizeof(rp.short_name));
> + snprintf((char *)rp.name, sizeof(rp.name), "%s", str);
> + snprintf((char *)rp.short_name, sizeof(rp.short_name), "%s", str);
> rp.supported_settings = L_CPU_TO_LE32(adapter->supported_settings);
> rp.current_settings = L_CPU_TO_LE32(adapter->current_settings);
>
> --
> 2.17.2

Applied, thanks.

--
Luiz Augusto von Dentz