[V2,i-g-t,2/3] Account for NULL character when using strncpy
diff mbox

Message ID d6f004f76c5f7524a7491f1b4f5feb23893f5b07.1529175003.git.rodrigosiqueiramelo@gmail.com
State New
Headers show

Commit Message

Rodrigo Siqueira June 17, 2018, 12:34 a.m. UTC
This patch fix the following gcc warning:

warning: ‘strncpy’ specified bound 32 equals destination size
[-Wstringop-truncation]
  strncpy(data->name, name, PARAM_NAME_MAX_SZ);

This error happens due to the '\0' character appended by strncpy. Notice
that reduces by one in the total of bytes to be copied, in this case, is
harmless because the strings received in the parameter already have
'\0'.

Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@gmail.com>
---
 lib/igt_aux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch
diff mbox

diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 1ea52efe..a605becc 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -1244,7 +1244,7 @@  static void igt_save_module_param(const char *name, const char *file_path)
 	data = calloc(1, sizeof (*data));
 	igt_assert(data);
 
-	strncpy(data->name, name, PARAM_NAME_MAX_SZ);
+	strncpy(data->name, name, PARAM_NAME_MAX_SZ - 1);
 
 	fd = open(file_path, O_RDONLY);
 	igt_assert(fd >= 0);