Skip to content

Commit 2f2f891

Browse files
committed
refactor: Use more generated pack functions for NGC savedata.
1 parent 0c05566 commit 2f2f891

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
@@ -48,7 +48,11 @@ static size_t buf_writer(cmp_ctx_t *ctx, const void *data, size_t count)
4848
// Buffer too small.
4949
return 0;
5050
}
51-
memcpy(&bp->bytes[bp->bytes_pos], data, count);
51+
if (data == nullptr) {
52+
assert(count == 0);
53+
} else {
54+
memcpy(&bp->bytes[bp->bytes_pos], data, count);
55+
}
5256
}
5357
bp->bytes_pos += count;
5458
return count;

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)