[Intel-gfx] [PATCH i-g-t 6/7] Fix truncate string in the strncpy

Rodrigo Siqueira rodrigosiqueiramelo at gmail.com
Sat Jul 7 23:23:42 UTC 2018


This patch fix the following GCC Warnings:

warning: ‘strncpy’ output truncated before terminating nul copying 36
bytes from a string of the same length [-Wstringop-truncation]
[..]

Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo at gmail.com>
---
 tests/perf.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tests/perf.c b/tests/perf.c
index 95048bfa..031bcee8 100644
--- a/tests/perf.c
+++ b/tests/perf.c
@@ -3693,7 +3693,7 @@ test_invalid_create_userspace_config(void)
 	igt_assert_eq(__i915_perf_add_config(drm_fd, &config), -EINVAL);
 
 	/* invalid mux_regs */
-	strncpy(config.uuid, uuid, sizeof(config.uuid));
+	strncpy(config.uuid, uuid, strlen(config.uuid));
 	config.n_mux_regs = 1;
 	config.mux_regs_ptr = to_user_pointer(invalid_mux_regs);
 	config.n_boolean_regs = 0;
@@ -3702,7 +3702,7 @@ test_invalid_create_userspace_config(void)
 	igt_assert_eq(__i915_perf_add_config(drm_fd, &config), -EINVAL);
 
 	/* empty config */
-	strncpy(config.uuid, uuid, sizeof(config.uuid));
+	strncpy(config.uuid, uuid, strlen(config.uuid));
 	config.n_mux_regs = 0;
 	config.mux_regs_ptr = to_user_pointer(mux_regs);
 	config.n_boolean_regs = 0;
@@ -3711,7 +3711,7 @@ test_invalid_create_userspace_config(void)
 	igt_assert_eq(__i915_perf_add_config(drm_fd, &config), -EINVAL);
 
 	/* empty config with null pointers */
-	strncpy(config.uuid, uuid, sizeof(config.uuid));
+	strncpy(config.uuid, uuid, strlen(config.uuid));
 	config.n_mux_regs = 1;
 	config.mux_regs_ptr = to_user_pointer(NULL);
 	config.n_boolean_regs = 2;
@@ -3722,7 +3722,7 @@ test_invalid_create_userspace_config(void)
 	igt_assert_eq(__i915_perf_add_config(drm_fd, &config), -EINVAL);
 
 	/* invalid pointers */
-	strncpy(config.uuid, uuid, sizeof(config.uuid));
+	strncpy(config.uuid, uuid, strlen(config.uuid));
 	config.n_mux_regs = 42;
 	config.mux_regs_ptr = to_user_pointer((void *) 0xDEADBEEF);
 	config.n_boolean_regs = 0;
@@ -3809,7 +3809,7 @@ test_create_destroy_userspace_config(void)
 		i915_perf_remove_config(drm_fd, config_id);
 
 	memset(&config, 0, sizeof(config));
-	strncpy(config.uuid, uuid, sizeof(config.uuid));
+	strncpy(config.uuid, uuid, strlen(config.uuid));
 
 	config.n_mux_regs = 1;
 	config.mux_regs_ptr = to_user_pointer(mux_regs);
-- 
2.18.0



More information about the Intel-gfx mailing list