qemu-ppc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-ppc] [PATCH v3 06/25] gdbstub: Use size_t to hold GDBState::last_p


From: Philippe Mathieu-Daudé
Subject: [Qemu-ppc] [PATCH v3 06/25] gdbstub: Use size_t to hold GDBState::last_packet_len
Date: Wed, 20 Feb 2019 02:02:13 +0100

In put_packet_binary() we have:

    uint8_t *p;
    for(;;) {
        p = s->last_packet;
        *(p++) = ...
        s->last_packet_len = p - s->last_packet;
        put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len);

The 'p' pointer start at s->last_packet, then is only incremented.
Since we have "p >= s->last_packet", we are sure than
"p - s->last_packet >= 0", thus "p - s->last_packet" is positive.

The few other places where s->last_packet_len is set is with constant
positive values.

It makes sense to use size_t to hold last_packet_len values.

Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
 gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdbstub.c b/gdbstub.c
index 76eca3bb7e..69340d7cd1 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -323,7 +323,7 @@ typedef struct GDBState {
     int line_sum; /* running checksum */
     int line_csum; /* checksum at the end of the packet */
     uint8_t last_packet[MAX_PACKET_LENGTH + 4];
-    int last_packet_len;
+    size_t last_packet_len;
     int signal;
 #ifdef CONFIG_USER_ONLY
     int fd;
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]