[PATCH i-g-t v2 1/2] lib/igt_sysfs: Use same var for sizeof()

Rodrigo Vivi rodrigo.vivi at intel.com
Thu Feb 22 21:29:09 UTC 2024


On Thu, Feb 22, 2024 at 11:33:25AM -0800, Lucas De Marchi wrote:
> Let's guarantee we always pass the same pointer to vsnprintf: if we are
> using the array size, pass that instead of buf that could point to
> something else in an eventual refactor.
> 
> Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
> ---
>  lib/igt_sysfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
> index 51b610114..2b0225138 100644
> --- a/lib/igt_sysfs.c
> +++ b/lib/igt_sysfs.c
> @@ -513,7 +513,7 @@ int igt_sysfs_vprintf(int dir, const char *attr, const char *fmt, va_list ap)
>  		return -errno;
>  
>  	va_copy(tmp, ap);
> -	ret = vsnprintf(buf, sizeof(stack), fmt, tmp);
> +	ret = vsnprintf(stack, sizeof(stack), fmt, tmp);

indeed safer (thinking about the possible refactors)

perhaps we can even move *buf = stack from the begin of
the function to an else of the if(ret > sizeof(stack))?

anyway, this is already much better

Reviewed-by: Rodrigo Vivi <rodrigo.vivi at intel.com>


>  	va_end(tmp);
>  	if (igt_debug_on(ret < 0))
>  		return -EINVAL;
> -- 
> 2.43.0
> 


More information about the igt-dev mailing list