]> xenbits.xensource.com Git - seabios.git/commitdiff
sercon: Fix missing GET_LOW() to access rx_bytes
authorKevin O'Connor <kevin@koconnor.net>
Thu, 20 Jan 2022 00:07:47 +0000 (19:07 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Thu, 27 Jan 2022 16:28:41 +0000 (11:28 -0500)
The variable rx_bytes is marked VARLOW, but there was a missing
GET_LOW() to access rx_bytes.  Fix by copying rx_bytes to a local
variable and avoid the repetitive segment memory accesses.

Reported-by: Gabe Black <gabe.black@gmail.com>
Signed-off-by: Volker RĂ¼melin <vr_qemu@t-online.de>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
src/sercon.c

index 66a1f2412e771b7222dd794d932d4c479d7935f4..3019d9b46ab8c011bb06a07731dcff270377c993 100644 (file)
@@ -626,7 +626,7 @@ sercon_check_event(void)
     u16 addr = GET_LOW(sercon_port);
     u16 keycode;
     u8 byte, count = 0;
-    int seq, chr;
+    int seq;
 
     // check to see if there is a active serial port
     if (!addr)
@@ -640,20 +640,23 @@ sercon_check_event(void)
     // read all available data
     while (inb(addr + SEROFF_LSR) & 0x01) {
         byte = inb(addr + SEROFF_DATA);
-        if (GET_LOW(rx_bytes) < sizeof(rx_buf)) {
-            SET_LOW(rx_buf[rx_bytes], byte);
-            SET_LOW(rx_bytes, GET_LOW(rx_bytes) + 1);
+        u8 rb = GET_LOW(rx_bytes);
+        if (rb < sizeof(rx_buf)) {
+            SET_LOW(rx_buf[rb], byte);
+            SET_LOW(rx_bytes, rb + 1);
             count++;
         }
     }
 
     for (;;) {
         // no (more) input data
-        if (!GET_LOW(rx_bytes))
+        u8 rb = GET_LOW(rx_bytes);
+        if (!rb)
             return;
 
         // lookup escape sequences
-        if (GET_LOW(rx_bytes) > 1 && GET_LOW(rx_buf[0]) == 0x1b) {
+        u8 next_char = GET_LOW(rx_buf[0]);
+        if (rb > 1 && next_char == 0x1b) {
             seq = findseq();
             if (seq >= 0) {
                 enqueue_key(GET_GLOBAL(termseq[seq].keycode));
@@ -664,12 +667,11 @@ sercon_check_event(void)
 
         // Seems we got a escape sequence we didn't recognise.
         //  -> If we received data wait for more, maybe it is just incomplete.
-        if (GET_LOW(rx_buf[0]) == 0x1b && count)
+        if (next_char == 0x1b && count)
             return;
 
         // Handle input as individual char.
-        chr = GET_LOW(rx_buf[0]);
-        keycode = ascii_to_keycode(chr);
+        keycode = ascii_to_keycode(next_char);
         if (keycode)
             enqueue_key(keycode);
         shiftbuf(1);