From: Paolo Bonzini Date: Wed, 3 May 2017 10:44:41 +0000 (+0200) Subject: jazz_led: fix bad snprintf X-Git-Tag: v2.10.0-rc0~202^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9c6ab62c760e333a6cf0f3f9ab021633723434c;p=thirdparty%2Fqemu.git jazz_led: fix bad snprintf 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. Signed-off-by: Paolo Bonzini Reviewed-by: Markus Armbruster Reviewed-by: Laurent Vivier Signed-off-by: Michael Tokarev --- diff --git a/hw/display/jazz_led.c b/hw/display/jazz_led.c index b72fdb17179..3c97d564347 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,