From: Peter Maydell <[email protected]>

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 <[email protected]>
Reviewed-by: Marc-AndrĂ© Lureau <[email protected]>
Message-ID: <[email protected]>
---
 ui/vt100.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ui/vt100.c b/ui/vt100.c
index e2fba822523..7e373766bc1 100644
--- a/ui/vt100.c
+++ b/ui/vt100.c
@@ -61,7 +61,7 @@ static void image_bitblt(pixman_image_t *image,
                            xs, ys, 0, 0, xd, yd, w, h);
 }
 
-static void vt100_putcharxy(QemuVT100 *vt, int x, int y, int ch,
+static void vt100_putcharxy(QemuVT100 *vt, int x, int y, uint8_t ch,
                             TextAttributes *t_attrib)
 {
     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)
     return *state;
 }
 
-static void vt100_put_one(QemuVT100 *vt, int ch)
+static void vt100_put_one(QemuVT100 *vt, uint8_t ch)
 {
     TextCell *c;
     int y1;
@@ -606,7 +606,7 @@ static void vt100_restore_cursor(QemuVT100 *vt)
     vt->t_attrib = vt->t_attrib_saved;
 }
 
-static void vt100_putchar(QemuVT100 *vt, int ch)
+static void vt100_putchar(QemuVT100 *vt, uint8_t ch)
 {
     int i;
     int x, y;
-- 
2.54.0


Reply via email to