Skip to content

Commit

Permalink
math: replace void * with uint8_t *
Browse files Browse the repository at this point in the history
Pointer math on void pointers is undefined. With GCC it is the same as a
char pointer, but MSVC simply refuses to compile them.

Replace math on `void *` with math on `uint8_t *`.

As a side effect, this helps to build under MSVC.

Signed-off-by: Sean Cross <[email protected]>
  • Loading branch information
xobs committed Nov 29, 2023
1 parent 672dad7 commit d66c4b5
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/gdb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ static void handle_v_packet(char *packet, const size_t plen)
/* Write Flash Memory */
const uint32_t count = plen - bin;
DEBUG_GDB("Flash Write %08" PRIX32 " %08" PRIX32 "\n", addr, count);
if (cur_target && target_flash_write(cur_target, addr, (void *)packet + bin, count))
if (cur_target && target_flash_write(cur_target, addr, (uint8_t *)packet + bin, count))
gdb_putpacketz("OK");
else {
target_flash_complete(cur_target);
Expand Down
2 changes: 1 addition & 1 deletion src/rtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ uint32_t rtt_aligned_mem_read(target_s *t, void *dest, target_addr_t src, size_t
return target_mem_read(t, dest, src, len);

const uint32_t retval = target_mem_read(t, dest, src0, len0);
memmove(dest, dest + offset, len);
memmove(dest, (uint8_t *)dest + offset, len);
return retval;
}

Expand Down
8 changes: 4 additions & 4 deletions src/target/ch32f1.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static bool ch32f1_wait_flash_ready(target_s *t, uint32_t addr)
}

/* Fast flash for ch32. Load 128 bytes chunk and then write them */
static int ch32f1_upload(target_s *t, uint32_t dest, const void *src, uint32_t offset)
static int ch32f1_upload(target_s *t, uint32_t dest, const uint8_t *src, uint32_t offset)
{
volatile uint32_t sr, magic;
const uint32_t *ss = (const uint32_t *)(src + offset);
Expand Down Expand Up @@ -319,7 +319,7 @@ static bool ch32f1_flash_write(target_flash_s *f, target_addr_t dest, const void
size_t length = len;
#ifdef CH32_VERIFY
target_addr_t org_dest = dest;
const void *org_src = src;
const uint8_t *org_src = (const uint8_t *)src;
#endif
DEBUG_INFO("CH32: flash write 0x%" PRIx32 " ,size=%" PRIu32 "\n", dest, (uint32_t)len);

Expand All @@ -337,7 +337,7 @@ static bool ch32f1_flash_write(target_flash_s *f, target_addr_t dest, const void
return false;

for (size_t i = 0; i < 8U; i++) {
if (ch32f1_upload(t, dest, src, i * 16U)) {
if (ch32f1_upload(t, dest, (const uint8_t *)src, i * 16U)) {
DEBUG_ERROR("Cannot upload to buffer\n");
return false;
}
Expand All @@ -359,7 +359,7 @@ static bool ch32f1_flash_write(target_flash_s *f, target_addr_t dest, const void
else
length = 0;
dest += 128U;
src += 128U;
src = (const uint8_t *)src + 128U;

sr = target_mem_read32(t, FLASH_SR); // 13
ch32f1_flash_lock(t);
Expand Down
2 changes: 1 addition & 1 deletion src/target/kinetis.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ static bool kinetis_flash_cmd_write(target_flash_s *f, target_addr_t dest, const
else
len = 0;
dest += kf->write_len;
src += kf->write_len;
src = (const uint8_t *)src + kf->write_len;
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/target/renesas.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ static bool renesas_rv40_flash_write(target_flash_s *const f, target_addr_t dest
target_mem_write16(t, RV40_CMD, *(uint16_t *)src);

/* 2 bytes of data */
src += 2U;
src = (const uint8_t *)src + 2U;
}

/* Issue write end command */
Expand Down
4 changes: 2 additions & 2 deletions src/target/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void target_regs_read(target_s *t, void *data)
t->regs_read(t, data);
else {
for (size_t x = 0, i = 0; x < t->regs_size;)
x += target_reg_read(t, i++, data + x, t->regs_size - x);
x += target_reg_read(t, i++, (uint8_t *)data + x, t->regs_size - x);
}
}

Expand All @@ -323,7 +323,7 @@ void target_regs_write(target_s *t, const void *data)
t->regs_write(t, data);
else {
for (size_t x = 0, i = 0; x < t->regs_size;)
x += target_reg_write(t, i++, data + x, t->regs_size - x);
x += target_reg_write(t, i++, (const uint8_t *)data + x, t->regs_size - x);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/target/target_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static bool flash_buffered_flush(target_flash_s *flash)
return result;
}

static bool flash_buffered_write(target_flash_s *flash, target_addr_t dest, const void *src, size_t len)
static bool flash_buffered_write(target_flash_s *flash, target_addr_t dest, const uint8_t *src, size_t len)
{
bool result = true; /* Catch false returns with &= */
while (len) {
Expand Down Expand Up @@ -292,7 +292,7 @@ bool target_flash_write(target_s *target, target_addr_t dest, const void *src, s
}

dest = local_end_addr;
src += local_length;
src = (const uint8_t *)src + local_length;
len -= local_length;
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion src/target/target_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct target_flash {
flash_erase_func erase; /* Erase a range of flash */
flash_write_func write; /* Write to flash */
flash_done_func done; /* Finish flash operations */
void *buf; /* Buffer for flash operations */
uint8_t *buf; /* Buffer for flash operations */
target_addr_t buf_addr_base; /* Address of block this buffer is for */
target_addr_t buf_addr_low; /* Address of lowest byte written */
target_addr_t buf_addr_high; /* Address of highest byte written */
Expand Down

0 comments on commit d66c4b5

Please sign in to comment.