[PATCH] display/disp_hcms29xx fix string turncation warning
Sebastian Huber
sebastian.huber at embedded-brains.de
Mon Sep 7 06:38:28 UTC 2020
On 03/09/2020 16:46, Aschref Ben-Thabet wrote:
> From: Aschref Ben Thabet <aschref.ben-thabet at embedded-brains.de>
>
> strncpy
Please use the strncpy() style for functions in commit messages and
comments.
> is unsafe if the terminating NULL
There are NULL pointers and NUL characters, see
https://www.man7.org/linux/man-pages/man7/ascii.7.html
> is missing, as it may copy
> more characters than fit in the destination area
No, the strncpy() does not overwrite the destination area if the size
parameter is valid. I doesn't terminate the destination string if the
source is too long.
>
> Replace it by the safer strlcpy() and fix the string
> turncation warnings.
> ---
> bsps/shared/dev/display/disp_hcms29xx.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/bsps/shared/dev/display/disp_hcms29xx.c b/bsps/shared/dev/display/disp_hcms29xx.c
> index 5730b36ea9..fb88f66343 100644
> --- a/bsps/shared/dev/display/disp_hcms29xx.c
> +++ b/bsps/shared/dev/display/disp_hcms29xx.c
> @@ -589,10 +589,9 @@ static rtems_task disp_hcms29xx_update_task
> RTEMS_WAIT,RTEMS_NO_TIMEOUT);
> }
> if (rc == RTEMS_SUCCESSFUL) {
> - strncpy(softc_ptr->disp_param.disp_buffer,
> + strlcpy(softc_ptr->disp_param.disp_buffer,
> softc_ptr->disp_param.trns_buffer,
> sizeof(softc_ptr->disp_param.disp_buffer));
> - softc_ptr->disp_param.disp_buffer[sizeof(softc_ptr->disp_param.disp_buffer)-1] = '\0';
> softc_ptr->disp_param.disp_buf_cnt =
> (int) strlen(softc_ptr->disp_param.disp_buffer);
> }
Please check what strlcpy() returns and use it to get rid of the
strlen() call.
More information about the devel
mailing list