]> git.sur5r.net Git - openocd/commitdiff
gdb_server: use strndup to allocate debug messages
authorSpencer Oliver <spen@spen-soft.co.uk>
Thu, 1 Dec 2011 12:48:31 +0000 (12:48 +0000)
committerSpencer Oliver <spen@spen-soft.co.uk>
Fri, 2 Dec 2011 12:26:04 +0000 (12:26 +0000)
Lets be consistent and use strndup to allocate the debug buffer.

Change-Id: I535ad270ebfeae6e09d28372ab3749c822971223
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/245
Tested-by: jenkins
Reviewed-by: Øyvind Harboe <oyvindharboe@gmail.com>
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
src/server/gdb_server.c

index 93aa8edc5d753499bb5228799d7088e34088bcb9..537513a1b6b831179ac8a405ef02d44170fa1e75 100644 (file)
@@ -44,7 +44,6 @@
 #include "rtos/rtos.h"
 #include "target/smp.h"
 
-
 /**
  * @file
  * GDB server implementation.
@@ -77,7 +76,6 @@ struct gdb_connection
        bool mem_write_error;
 };
 
-
 #if 0
 #define _DEBUG_GDB_IO_
 #endif
@@ -245,9 +243,7 @@ static int gdb_get_char_inner(struct connection *connection, int* next_char)
        }
 
 #ifdef _DEBUG_GDB_IO_
-       debug_buffer = malloc(gdb_con->buf_cnt + 1);
-       memcpy(debug_buffer, gdb_con->buffer, gdb_con->buf_cnt);
-       debug_buffer[gdb_con->buf_cnt] = 0;
+       debug_buffer = strndup(gdb_con->buffer, gdb_con->buf_cnt);
        LOG_DEBUG("received '%s'", debug_buffer);
        free(debug_buffer);
 #endif
@@ -389,9 +385,7 @@ static int gdb_put_packet_inner(struct connection *connection,
        while (1)
        {
 #ifdef _DEBUG_GDB_IO_
-               debug_buffer = malloc(len + 1);
-               memcpy(debug_buffer, buffer, len);
-               debug_buffer[len] = 0;
+               debug_buffer = strndup(buffer, len);
                LOG_DEBUG("sending packet '$%s#%2.2x'", debug_buffer, my_checksum);
                free(debug_buffer);
 #endif