From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: <igt-dev@lists.freedesktop.org>,
Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Subject: Re: [PATCH i-g-t v2 1/2] lib/igt_sysfs: Use same var for sizeof()
Date: Thu, 22 Feb 2024 16:29:09 -0500 [thread overview]
Message-ID: <Zde8paI0Rj5I8Bz4@intel.com> (raw)
In-Reply-To: <20240222193326.3004623-1-lucas.demarchi@intel.com>
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@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@intel.com>
> va_end(tmp);
> if (igt_debug_on(ret < 0))
> return -EINVAL;
> --
> 2.43.0
>
next prev parent reply other threads:[~2024-02-22 21:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-22 19:33 [PATCH i-g-t v2 1/2] lib/igt_sysfs: Use same var for sizeof() Lucas De Marchi
2024-02-22 19:33 ` [PATCH i-g-t v2 2/2] lib/igt_sysfs: make sure to write empty strings Lucas De Marchi
2024-02-26 21:11 ` Janusz Krzysztofik
2024-02-27 5:26 ` Lucas De Marchi
2024-02-22 20:15 ` ✓ CI.xeBAT: success for series starting with [i-g-t,v2,1/2] lib/igt_sysfs: Use same var for sizeof() Patchwork
2024-02-22 20:23 ` ✓ Fi.CI.BAT: " Patchwork
2024-02-22 21:29 ` Rodrigo Vivi [this message]
2024-02-23 7:01 ` ✗ Fi.CI.IGT: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zde8paI0Rj5I8Bz4@intel.com \
--to=rodrigo.vivi@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=janusz.krzysztofik@linux.intel.com \
--cc=lucas.demarchi@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox