From: Spencer Oliver Date: Thu, 1 Dec 2011 12:48:31 +0000 (+0000) Subject: gdb_server: use strndup to allocate debug messages X-Git-Tag: v0.6.0-rc1~381 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=3500109fc736a4818b34c8c7c8e7ebea59bdd47b;p=openocd gdb_server: use strndup to allocate debug messages Lets be consistent and use strndup to allocate the debug buffer. Change-Id: I535ad270ebfeae6e09d28372ab3749c822971223 Signed-off-by: Spencer Oliver Reviewed-on: http://openocd.zylin.com/245 Tested-by: jenkins Reviewed-by: Øyvind Harboe Reviewed-by: Andreas Fritiofson --- diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 93aa8edc..537513a1 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -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