Skip to content

Commit fad18b9

Browse files
committed
refactor: Use more generated pack functions for NGC savedata.
1 parent ee8615b commit fad18b9

File tree

3 files changed

+249
-83
lines changed

3 files changed

+249
-83
lines changed

toxcore/bin_pack.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ static size_t buf_writer(cmp_ctx_t *ctx, const void *data, size_t data_size)
4747
// Buffer too small.
4848
return 0;
4949
}
50-
memcpy(&bp->bytes[bp->bytes_pos], data, data_size);
50+
if (data == nullptr) {
51+
assert(data_size == 0);
52+
} else {
53+
memcpy(&bp->bytes[bp->bytes_pos], data, data_size);
54+
}
5155
}
5256
bp->bytes_pos += data_size;
5357
return data_size;

toxcore/bin_pack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ non_null() bool bin_pack_u64(Bin_Pack *bp, uint64_t val);
173173
/** @brief Pack an empty array member as a MessagePack nil value. */
174174
non_null() bool bin_pack_nil(Bin_Pack *bp);
175175
/** @brief Pack a byte array as MessagePack bin. */
176-
non_null() bool bin_pack_bin(Bin_Pack *bp, const uint8_t *data, uint32_t length);
176+
non_null(1) nullable(2) bool bin_pack_bin(Bin_Pack *bp, const uint8_t *data, uint32_t length);
177177
/** @brief Start packing a custom binary representation.
178178
*
179179
* A call to this function must be followed by exactly `size` bytes packed by functions below.

0 commit comments

Comments
 (0)