Skip to content

Commit

Permalink
fix _z_bytes_move to account for aliased vector
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisBiryukov91 committed Feb 27, 2025
1 parent b2e97d6 commit 6c4e272
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/collections/bytes.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ _z_slice_t _z_bytes_try_get_contiguous(const _z_bytes_t *bs) {
}

z_result_t _z_bytes_move(_z_bytes_t *dst, _z_bytes_t *src) {
if (src->_slices._aliased) {
*dst = _z_bytes_null();
_z_bytes_t csrc;
_Z_RETURN_IF_ERR(_z_arc_slice_svec_copy(&csrc._slices, &src->_slices, false));
*src = csrc;
}
*dst = *src;
*src = _z_bytes_null();
return _Z_RES_OK;
Expand Down
4 changes: 2 additions & 2 deletions src/net/sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ z_result_t _z_sample_move(_z_sample_t *dst, _z_sample_t *src) {
*dst = _z_sample_null();
_Z_RETURN_IF_ERR(_z_keyexpr_move(&dst->keyexpr, &src->keyexpr));
_Z_CLEAN_RETURN_IF_ERR(_z_encoding_move(&dst->encoding, &src->encoding), _z_sample_clear(dst));
_z_bytes_move(&dst->payload, &src->payload);
_Z_CLEAN_RETURN_IF_ERR(_z_bytes_move(&dst->payload, &src->payload), _z_sample_clear(dst));
_Z_CLEAN_RETURN_IF_ERR(_z_bytes_move(&dst->attachment, &src->attachment), _z_sample_clear(dst));
_z_timestamp_move(&dst->timestamp, &src->timestamp);
_z_bytes_move(&dst->attachment, &src->attachment);
dst->qos = src->qos;
dst->reliability = src->reliability;
dst->kind = src->kind;
Expand Down
3 changes: 2 additions & 1 deletion src/protocol/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ z_result_t _z_hello_move(_z_hello_t *dst, _z_hello_t *src) {
}

z_result_t _z_value_move(_z_value_t *dst, _z_value_t *src) {
_z_bytes_move(&dst->payload, &src->payload);
*dst = _z_value_null();
_Z_RETURN_IF_ERR(_z_bytes_move(&dst->payload, &src->payload));
_Z_CLEAN_RETURN_IF_ERR(_z_encoding_move(&dst->encoding, &src->encoding), _z_value_clear(dst));
return _Z_RES_OK;
}

0 comments on commit 6c4e272

Please sign in to comment.