diff mbox series

[v3,06/25] gdbstub: Use size_t to hold GDBState::last_packet_len

Message ID 20190220010232.18731-7-philmd@redhat.com
State New
Headers show
Series chardev: Convert qemu_chr_write() to take a size_t argument | expand

Commit Message

Philippe Mathieu-Daudé Feb. 20, 2019, 1:02 a.m. UTC
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é <philmd@redhat.com>
---
 gdbstub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Marc-André Lureau Feb. 20, 2019, 10:59 a.m. UTC | #1
On Wed, Feb 20, 2019 at 2:04 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> 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é <philmd@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  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
>
diff mbox series

Patch

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;