aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorPhilip Nye <philipnye@users.sf.net>2011-11-14 20:11:51 +0000
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>2011-11-17 23:10:59 +0000
commite5e2408680e860cce669b150374188985c442c41 (patch)
tree913b27e3d91c64a8540931ef64396a47536298bc /src/server
parent950f2405197661974225a578630e44667639ccb6 (diff)
downloadriscv-openocd-e5e2408680e860cce669b150374188985c442c41.zip
riscv-openocd-e5e2408680e860cce669b150374188985c442c41.tar.gz
riscv-openocd-e5e2408680e860cce669b150374188985c442c41.tar.bz2
gdb: Potential rounding error in reg_packet_size gdb_get_registers_packet
The calculation for reg_packet_size in gdb_get_registers_packet() could generate a wrong result in the case of multiple registers whose size is not a multiple of 8. The current calculation sums the sizes for all registers then rounds the result up to the next multiple of 8. Instead it should round each register size up individually and sum the results for all registers. Change-Id: Idfb5e5eeee0e69a6889dbe9769c0bf17feacb63b Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk> Reviewed-on: http://openocd.zylin.com/200 Tested-by: jenkins Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Diffstat (limited to 'src/server')
-rw-r--r--src/server/gdb_server.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index cbc2b40..4dd9bd1 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -1058,12 +1058,12 @@ static int gdb_get_registers_packet(struct connection *connection,
for (i = 0; i < reg_list_size; i++)
{
- reg_packet_size += reg_list[i]->size;
+ reg_packet_size += DIV_ROUND_UP(reg_list[i]->size, 8) * 2;
}
assert(reg_packet_size > 0);
- reg_packet = malloc(DIV_ROUND_UP(reg_packet_size, 8) * 2);
+ reg_packet = malloc(reg_packet_size);
reg_packet_p = reg_packet;
for (i = 0; i < reg_list_size; i++)
@@ -1077,13 +1077,13 @@ static int gdb_get_registers_packet(struct connection *connection,
#ifdef _DEBUG_GDB_IO_
{
char *reg_packet_p;
- reg_packet_p = strndup(reg_packet, DIV_ROUND_UP(reg_packet_size, 8) * 2);
+ reg_packet_p = strndup(reg_packet, reg_packet_size);
LOG_DEBUG("reg_packet: %s", reg_packet_p);
free(reg_packet_p);
}
#endif
- gdb_put_packet(connection, reg_packet, DIV_ROUND_UP(reg_packet_size, 8) * 2);
+ gdb_put_packet(connection, reg_packet, reg_packet_size);
free(reg_packet);
free(reg_list);