[igt-dev] [PATCH i-g-t] tests/perf: Use memcpy for UUIDs for oa_configs

Ser, Simon simon.ser at intel.com
Thu May 16 14:17:48 UTC 2019


On Thu, 2019-05-16 at 16:20 +0300, Arkadiusz Hiler wrote:
> drm_i915_perf_oa_config defines uuid as char[36], which does not leave
> space for the terminating NULL. Newer GCC and the fortification options
> leave us with the following complaint:
> 
>    warning: ‘__builtin_strncpy’ output truncated before terminating nul copying 36 bytes from a string of the same length [-Wstringop-truncation]
> 
> Let's switch to memcpy() which does not care about the terminating NULL.
> 
> Cc: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
> Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler at intel.com>

Reviewed-by: Simon Ser <simon.ser at intel.com>

> ---
>  tests/perf.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/tests/perf.c b/tests/perf.c
> index f2c0aeb8..5ad8b2db 100644
> --- a/tests/perf.c
> +++ b/tests/perf.c
> @@ -3670,7 +3670,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));
> +	memcpy(config.uuid, uuid, sizeof(config.uuid));
>  	config.n_mux_regs = 1;
>  	config.mux_regs_ptr = to_user_pointer(invalid_mux_regs);
>  	config.n_boolean_regs = 0;
> @@ -3679,7 +3679,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));
> +	memcpy(config.uuid, uuid, sizeof(config.uuid));
>  	config.n_mux_regs = 0;
>  	config.mux_regs_ptr = to_user_pointer(mux_regs);
>  	config.n_boolean_regs = 0;
> @@ -3688,7 +3688,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));
> +	memcpy(config.uuid, uuid, sizeof(config.uuid));
>  	config.n_mux_regs = 1;
>  	config.mux_regs_ptr = to_user_pointer(NULL);
>  	config.n_boolean_regs = 2;
> @@ -3699,7 +3699,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));
> +	memcpy(config.uuid, uuid, sizeof(config.uuid));
>  	config.n_mux_regs = 42;
>  	config.mux_regs_ptr = to_user_pointer((void *) 0xDEADBEEF);
>  	config.n_boolean_regs = 0;
> @@ -3786,7 +3786,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));
> +	memcpy(config.uuid, uuid, sizeof(config.uuid));
>  
>  	config.n_mux_regs = 1;
>  	config.mux_regs_ptr = to_user_pointer(mux_regs);


More information about the igt-dev mailing list