All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: marcandre.lureau@redhat.com
Cc: qemu-devel@nongnu.org,  Michael Roth <michael.roth@amd.com>
Subject: Re: [PATCH] tests/unit: fix a -Wformat-trunction warning
Date: Wed, 10 Aug 2022 14:24:18 +0200	[thread overview]
Message-ID: <87bkssb825.fsf@pond.sub.org> (raw)
In-Reply-To: <20220810121513.1356081-1-marcandre.lureau@redhat.com> (marcandre lureau's message of "Wed, 10 Aug 2022 16:15:13 +0400")

Typo in subject, it's -Wformat-truncation

marcandre.lureau@redhat.com writes:

> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>
> ../tests/test-qobject-input-visitor.c: In function ‘test_visitor_in_list’:
> ../tests/test-qobject-input-visitor.c:454:49: warning: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 6 [-Wformat-truncation=]
>   454 |         snprintf(string, sizeof(string), "string%d", i);
>       |                                                 ^~
> ../tests/test-qobject-input-visitor.c:454:42: note: directive argument in the range [0, 2147483606]
>   454 |         snprintf(string, sizeof(string), "string%d", i);
>       |                                          ^~~~~~~~~~
> ../tests/test-qobject-input-visitor.c:454:9: note: ‘snprintf’ output between 8 and 17 bytes into a destination of size 12
>   454 |         snprintf(string, sizeof(string), "string%d", i);
>       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Not trying to be clever, this is called 3 times during tests,
> let simply use g_strdup_printf().
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  tests/unit/test-qobject-input-visitor.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/tests/unit/test-qobject-input-visitor.c b/tests/unit/test-qobject-input-visitor.c
> index 14329dabcf..5f614afdbf 100644
> --- a/tests/unit/test-qobject-input-visitor.c
> +++ b/tests/unit/test-qobject-input-visitor.c
> @@ -447,9 +447,8 @@ static void test_visitor_in_list(TestInputVisitorData *data,
>      g_assert(head != NULL);
>  
>      for (i = 0, item = head; item; item = item->next, i++) {
> -        char string[12];
> +        g_autofree char *string = g_strdup_printf("string%d", i);
>  
> -        snprintf(string, sizeof(string), "string%d", i);
>          g_assert_cmpstr(item->value->string, ==, string);
>          g_assert_cmpint(item->value->integer, ==, 42 + i);
>      }

Even less clever would be char string[32].

Anyway, with the typo corrected:
Reviewed-by: Markus Armbruster <armbru@redhat.com>



  reply	other threads:[~2022-08-10 12:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-10 12:15 [PATCH] tests/unit: fix a -Wformat-trunction warning marcandre.lureau
2022-08-10 12:24 ` Markus Armbruster [this message]
2022-08-10 13:54   ` Philippe Mathieu-Daudé via
2022-08-12 10:23 ` Peter Maydell

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=87bkssb825.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=michael.roth@amd.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.