diff --git a/src/api/api.c b/src/api/api.c index 8a5c779e4..f4821b457 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -323,7 +323,7 @@ int8_t z_bytes_deserialize_into_string(const z_loaned_bytes_t *bytes, z_owned_st } // Convert bytes to string size_t len = _z_bytes_len(bytes); - *s->_val = _z_string_preallocate(_z_bytes_len(bytes)); + *s->_val = _z_string_preallocate(len); if (s->_val->len != len) return _Z_ERR_SYSTEM_OUT_OF_MEMORY; _z_bytes_to_buf(bytes, (uint8_t *)s->_val->val, len); return _Z_RES_OK; diff --git a/src/collections/arc_slice.c b/src/collections/arc_slice.c index 922ac9ca6..ac0e7bc9d 100644 --- a/src/collections/arc_slice.c +++ b/src/collections/arc_slice.c @@ -79,7 +79,6 @@ int8_t _z_arc_slice_move(_z_arc_slice_t* dst, _z_arc_slice_t* src) { int8_t _z_arc_slice_drop(_z_arc_slice_t* s) { _z_slice_rc_drop(&s->slice); - s->len = 0; - s->start = 0; + *s = _z_arc_slice_empty(); return _Z_RES_OK; } diff --git a/src/collections/bytes.c b/src/collections/bytes.c index 03c112e47..1d9695559 100644 --- a/src/collections/bytes.c +++ b/src/collections/bytes.c @@ -34,7 +34,7 @@ _z_bytes_t _z_bytes_null(void) { int8_t _z_bytes_copy(_z_bytes_t *dst, const _z_bytes_t *src) { _z_arc_slice_svec_copy(&dst->_slices, &src->_slices); - if (_z_arc_slice_svec_len(&dst->_slices) == _z_arc_slice_svec_len(&dst->_slices)) { + if (_z_arc_slice_svec_len(&dst->_slices) == _z_arc_slice_svec_len(&src->_slices)) { return _Z_RES_OK; } else { return _Z_ERR_SYSTEM_OUT_OF_MEMORY; @@ -93,7 +93,7 @@ size_t _z_bytes_to_buf(const _z_bytes_t *bytes, uint8_t *dst, size_t len) { size_t s_len = _z_arc_slice_len(s); size_t len_to_copy = remaining >= s_len ? s_len : remaining; memcpy(start, _z_arc_slice_data(s), len_to_copy); - start += s_len; + start += len_to_copy; remaining -= len_to_copy; } diff --git a/src/collections/vec.c b/src/collections/vec.c index af58c42c0..9acd13f85 100644 --- a/src/collections/vec.c +++ b/src/collections/vec.c @@ -167,7 +167,7 @@ void __z_svec_move_inner(void *dst, void *src, z_element_move_f move, size_t num void _z_svec_copy(_z_svec_t *dst, const _z_svec_t *src, z_element_copy_f copy, size_t element_size) { dst->_capacity = 0; dst->_len = 0; - dst->_val = z_malloc(sizeof(void *) * src->_capacity); + dst->_val = z_malloc(element_size * src->_capacity); if (dst->_val != NULL) { dst->_capacity = src->_capacity; dst->_len = src->_len; diff --git a/src/net/reply.c b/src/net/reply.c index 3df4b9fe2..43de427ba 100644 --- a/src/net/reply.c +++ b/src/net/reply.c @@ -93,12 +93,12 @@ _z_reply_t _z_reply_create(_z_keyexpr_t keyexpr, z_reply_tag_t tag, _z_id_t id, reply.data.replier_id = id; // Create sample _z_sample_t sample = _z_sample_null(); - sample.keyexpr = keyexpr; // FIXME: call z_keyexpr_move or copy - sample.encoding = encoding; // FIXME: call z_encoding_move or copy - _z_bytes_copy(&sample.payload, &payload); // FIXME: call z_bytes_move or copy + sample.keyexpr = keyexpr; // FIXME: call z_keyexpr_move or copy + sample.encoding = encoding; // FIXME: call z_encoding_move or copy + _z_bytes_copy(&sample.payload, &payload); sample.kind = kind; sample.timestamp = _z_timestamp_duplicate(timestamp); - _z_bytes_copy(&sample.attachment, &attachment); // FIXME: call z_bytes_move or copy + _z_bytes_copy(&sample.attachment, &attachment); // Create sample rc from value reply.data.sample = _z_sample_rc_new_from_val(sample); diff --git a/src/protocol/codec.c b/src/protocol/codec.c index 53b15a1a0..839ef0e42 100644 --- a/src/protocol/codec.c +++ b/src/protocol/codec.c @@ -270,12 +270,8 @@ int8_t _z_slice_val_decode_na(_z_slice_t *bs, _z_zbuf_t *zbf) { } int8_t _z_slice_decode_na(_z_slice_t *bs, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; - - ret |= _z_zsize_decode(&bs->len, zbf); - ret |= _z_slice_val_decode_na(bs, zbf); - - return ret; + _Z_RETURN_IF_ERR(_z_zsize_decode(&bs->len, zbf)); + return _z_slice_val_decode_na(bs, zbf); } int8_t _z_slice_val_decode(_z_slice_t *bs, _z_zbuf_t *zbf) { return _z_slice_val_decode_na(bs, zbf); } @@ -283,10 +279,8 @@ int8_t _z_slice_val_decode(_z_slice_t *bs, _z_zbuf_t *zbf) { return _z_slice_val int8_t _z_slice_decode(_z_slice_t *bs, _z_zbuf_t *zbf) { return _z_slice_decode_na(bs, zbf); } int8_t _z_bytes_decode(_z_bytes_t *bs, _z_zbuf_t *zbf) { - int8_t ret = _Z_RES_OK; _z_slice_t s; - ret = _z_slice_decode(&s, zbf); - if (ret != _Z_RES_OK) return ret; + _Z_RETURN_IF_ERR(_z_slice_decode(&s, zbf)); return _z_bytes_from_slice(bs, s); } diff --git a/src/protocol/codec/message.c b/src/protocol/codec/message.c index 7c8952295..608f9ba0f 100644 --- a/src/protocol/codec/message.c +++ b/src/protocol/codec/message.c @@ -446,9 +446,7 @@ int8_t _z_query_decode_extensions(_z_msg_ext_t *extension, void *ctx) { } case _Z_MSG_EXT_ENC_ZBUF | 0x03: { // Payload _z_zbuf_t zbf = _z_slice_as_zbuf(extension->_body._zbuf._val); - _Z_RETURN_IF_ERR(_z_encoding_decode(&msg->_ext_value.encoding, &zbf)); - _Z_RETURN_IF_ERR( - _z_bytes_from_buf(&msg->_ext_value.payload, (uint8_t *)_z_zbuf_start(&zbf), _z_zbuf_len(&zbf))); + ret = _z_value_decode(&msg->_ext_value, &zbf); break; } case _Z_MSG_EXT_ENC_ZBUF | 0x05: { // Attachment diff --git a/tests/z_client_test.c b/tests/z_client_test.c index 206573196..fea41db83 100644 --- a/tests/z_client_test.c +++ b/tests/z_client_test.c @@ -83,7 +83,7 @@ void reply_handler(const z_loaned_reply_t *reply, void *arg) { z_keyexpr_to_string(z_sample_keyexpr(sample), &k_str); z_owned_string_t value; z_bytes_deserialize_into_string(z_sample_payload(sample), &value); - assert(z_string_len(z_loan(value)) == strlen(res) + 1); + assert(z_string_len(z_loan(value)) == strlen(res)); assert(strncmp(res, z_string_data(z_loan(value)), strlen(res)) == 0); assert(_z_str_eq(z_loan(k_str)->val, res) == true);