Use (uint8_t *) for buf_(set|get)_u(32|64) instead of (void *)
This helps to uncover incorrect usage when a pointer to uint32_t is passed to those functions which leads to subtle bugs on BE systems. The reason is that it's normally assumed that any uint32_t variable holds its value in host byte order, but using but_set_u32 on it silently does implicit pointer conversion to (void *) and the assumption ends up broken without any indication. Change-Id: I48ffd190583d8aa32ec1fef8f1cdc0b4184e4546 Signed-off-by: Paul Fertser <fercerpav@gmail.com> Reviewed-on: http://openocd.zylin.com/2467 Tested-by: jenkins Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
This commit is contained in:
+1
-1
@@ -308,7 +308,7 @@ static int etb_write_reg(struct reg *reg, uint32_t value)
|
||||
fields[0].num_bits = 32;
|
||||
uint8_t temp0[4];
|
||||
fields[0].out_value = temp0;
|
||||
buf_set_u32(&temp0, 0, 32, value);
|
||||
buf_set_u32(temp0, 0, 32, value);
|
||||
fields[0].in_value = NULL;
|
||||
|
||||
fields[1].num_bits = 7;
|
||||
|
||||
+2
-2
@@ -318,7 +318,7 @@ struct reg_cache *etm_build_reg_cache(struct target *target,
|
||||
etm_core, 1);
|
||||
|
||||
etm_get_reg(reg_list);
|
||||
etm_ctx->config = buf_get_u32(&arch_info->value, 0, 32);
|
||||
etm_ctx->config = buf_get_u32(arch_info->value, 0, 32);
|
||||
config = etm_ctx->config;
|
||||
|
||||
/* figure ETM version then add base registers */
|
||||
@@ -334,7 +334,7 @@ struct reg_cache *etm_build_reg_cache(struct target *target,
|
||||
etm_core + 1, 1);
|
||||
etm_get_reg(reg_list + 1);
|
||||
etm_ctx->id = buf_get_u32(
|
||||
&arch_info[1].value, 0, 32);
|
||||
arch_info[1].value, 0, 32);
|
||||
LOG_DEBUG("ETM ID: %08x", (unsigned) etm_ctx->id);
|
||||
bcd_vers = 0x10 + (((etm_ctx->id) >> 4) & 0xff);
|
||||
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ enum {
|
||||
};
|
||||
|
||||
struct etm_reg {
|
||||
uint32_t value;
|
||||
uint8_t value[4];
|
||||
const struct etm_reg_info *reg_info;
|
||||
struct arm_jtag *jtag_info;
|
||||
};
|
||||
|
||||
+2
-2
@@ -64,9 +64,9 @@ int gdb_read_smp_packet(struct connection *connection,
|
||||
if (strncmp(packet, "jc", 2) == 0) {
|
||||
const uint32_t len = sizeof(target->gdb_service->core[0]);
|
||||
char hex_buffer[len * 2 + 1];
|
||||
char buffer[len];
|
||||
uint8_t buffer[len];
|
||||
buf_set_u32(buffer, 0, len * 8, target->gdb_service->core[0]);
|
||||
int pkt_len = hexify(hex_buffer, buffer, sizeof(buffer), sizeof(hex_buffer));
|
||||
int pkt_len = hexify(hex_buffer, (char *)buffer, sizeof(buffer), sizeof(hex_buffer));
|
||||
|
||||
retval = gdb_put_packet(connection, hex_buffer, pkt_len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user