Skip to content

Commit 9b46a08

Browse files
committed
cleanup: Never pass void* directly to memcpy.
It cannot be type-checked easily, so we avoid void pointers entirely.
1 parent 5d7b7a7 commit 9b46a08

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

toxcore/bin_pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static bool null_skipper(cmp_ctx_t *ctx, size_t count)
3636
non_null()
3737
static size_t buf_writer(cmp_ctx_t *ctx, const void *data, size_t count)
3838
{
39+
const uint8_t *bytes = (const uint8_t *)data;
3940
Bin_Pack *bp = (Bin_Pack *)ctx->buf;
4041
assert(bp != nullptr);
4142
const uint32_t new_pos = bp->bytes_pos + count;
@@ -48,7 +49,7 @@ static size_t buf_writer(cmp_ctx_t *ctx, const void *data, size_t count)
4849
// Buffer too small.
4950
return 0;
5051
}
51-
memcpy(&bp->bytes[bp->bytes_pos], data, count);
52+
memcpy(&bp->bytes[bp->bytes_pos], bytes, count);
5253
}
5354
bp->bytes_pos += count;
5455
return count;

toxcore/bin_unpack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ struct Bin_Unpack {
2121
non_null()
2222
static bool buf_reader(cmp_ctx_t *ctx, void *data, size_t limit)
2323
{
24+
uint8_t *bytes = (uint8_t *)data;
2425
Bin_Unpack *reader = (Bin_Unpack *)ctx->buf;
2526
assert(reader != nullptr && reader->bytes != nullptr);
2627
if (limit > reader->bytes_size) {
2728
return false;
2829
}
29-
memcpy(data, reader->bytes, limit);
30+
memcpy(bytes, reader->bytes, limit);
3031
reader->bytes += limit;
3132
reader->bytes_size -= limit;
3233
return true;

0 commit comments

Comments
 (0)