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 <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>
__archive__
Spencer Oliver 2011-12-01 12:48:31 +00:00
parent 5165afc005
commit 3500109fc7
1 changed files with 2 additions and 8 deletions

View 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