From: Laurent Vivier <lvivier@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, leon.alrae@imgtec.com
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH] jazz_led: fix bad snprintf
Date: Wed, 3 May 2017 12:51:10 +0200 [thread overview]
Message-ID: <b1a33b8f-8a36-1481-af0a-a10c4212af1e@redhat.com> (raw)
In-Reply-To: <20170503104441.1349-1-pbonzini@redhat.com>
On 03/05/2017 12:44, Paolo Bonzini wrote:
> Detected by GCC 7's -Wformat-truncation. snprintf writes at most
> 2 bytes here including the terminating NUL, so the result is
> truncated. In addition, the newline at the end is pointless.
> Fix the buffer size and the format string.
> ---
> hw/display/jazz_led.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/display/jazz_led.c b/hw/display/jazz_led.c
> index b72fdb1717..3c97d56434 100644
> --- a/hw/display/jazz_led.c
> +++ b/hw/display/jazz_led.c
> @@ -227,13 +227,13 @@ static void jazz_led_invalidate_display(void *opaque)
> static void jazz_led_text_update(void *opaque, console_ch_t *chardata)
> {
> LedState *s = opaque;
> - char buf[2];
> + char buf[3];
>
> dpy_text_cursor(s->con, -1, -1);
> qemu_console_resize(s->con, 2, 1);
>
> /* TODO: draw the segments */
> - snprintf(buf, 2, "%02hhx\n", s->segments);
> + snprintf(buf, 3, "%02hhx", s->segments);
> console_write_ch(chardata++, ATTR2CHTYPE(buf[0], QEMU_COLOR_BLUE,
> QEMU_COLOR_BLACK, 1));
> console_write_ch(chardata++, ATTR2CHTYPE(buf[1], QEMU_COLOR_BLUE,
Reviewed-by: Laurent Vivier <lvivier@redhat.com>
next prev parent reply other threads:[~2017-05-03 10:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-03 10:44 [Qemu-devel] [PATCH] jazz_led: fix bad snprintf Paolo Bonzini
2017-05-03 10:51 ` Laurent Vivier [this message]
2017-05-03 11:38 ` Markus Armbruster
2017-05-03 11:54 ` Paolo Bonzini
2017-05-03 12:12 ` [Qemu-devel] [Qemu-trivial] " Laurent Vivier
2017-05-03 12:56 ` [Qemu-devel] " Markus Armbruster
2017-05-03 13:10 ` Paolo Bonzini
2017-05-03 13:33 ` Markus Armbruster
2017-05-05 6:24 ` Michael Tokarev
2017-05-05 7:22 ` Paolo Bonzini
2017-05-05 9:47 ` Michael Tokarev
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=b1a33b8f-8a36-1481-af0a-a10c4212af1e@redhat.com \
--to=lvivier@redhat.com \
--cc=leon.alrae@imgtec.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).