@samitouri / QOSamiQemu / commits / 64ad80ef13

ui/vt100: Standardize on uint8_t for "ch" byte variables

The vt100 code is rather confused about how it handles bytes of data to be sent to the terminal: * vt100_input() takes a buffer of uint8_t * each byte is passed to vt100_putchar(), which takes "int ch" * that calls vt100_put_one(), which also takes "int ch" * vt100_put_one() sets TextCell::ch, which is uint8_t again * various places pass the TextCell:ch value to vt100_putcharxy(), which takes "int ch" again, but uses it unchecked as an index into a 256-entry array This confuses Coverity (e.g. CID 1659590) and the reader, who may be unsure whether the "int" variable really does hold only valid byte values 0..255 and whether we need to bounds-check before doing array dereferences. Standardize on keeping known-byte data in uint8_t all the way through. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260512104210.3330835-2-peter.maydell@linaro.org>

Peter Maydell committed May 12, 2026 at 11:42 UTC 64ad80ef132a058d7269d35d5cbc476c7990fd26
1 file changed +3 -3
ui/vt100.c
+3 -3
@@ -61,7 +61,7 @@ static void image_bitblt(pixman_image_t *image,
61 xs, ys, 0, 0, xd, yd, w, h);
62 }
63
64 -static void vt100_putcharxy(QemuVT100 *vt, int x, int y, int ch,
64 +static void vt100_putcharxy(QemuVT100 *vt, int x, int y, uint8_t ch,
65 TextAttributes *t_attrib)
66 {
67 static pixman_image_t *glyphs[256];
@@ -468,7 +468,7 @@ static uint32_t bh_utf8_decode(uint32_t *state, uint32_t *codep, uint32_t byte)
468 return *state;
469 }
470
471 -static void vt100_put_one(QemuVT100 *vt, int ch)
471 +static void vt100_put_one(QemuVT100 *vt, uint8_t ch)
472 {
473 TextCell *c;
474 int y1;
@@ -606,7 +606,7 @@ static void vt100_restore_cursor(QemuVT100 *vt)
606 vt->t_attrib = vt->t_attrib_saved;
607 }
608
609 -static void vt100_putchar(QemuVT100 *vt, int ch)
609 +static void vt100_putchar(QemuVT100 *vt, uint8_t ch)
610 {
611 int i;
612 int x, y;