[PATCH] display/disp_hcms29xx: Fix string truncation warning

Aschref Ben-Thabet aschref.ben-thabet at embedded-brains.de
Tue Sep 15 09:10:28 UTC 2020


From: Aschref Ben Thabet <aschref.ben-thabet at embedded-brains.de>

Strncpy() is unsafe if the terminating NUL is missing. Replace it by the
safer strlcpy() and fix the string truncation warning,since the
strlcpy() function returns the total length of the string it tried to
create,that means: the length of src.
---
 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);
       }
-- 
2.26.2



More information about the devel mailing list