Skip to content

Commit

Permalink
fix more lints
Browse files Browse the repository at this point in the history
  • Loading branch information
p-avital committed Jul 12, 2023
1 parent 8f52d50 commit 5a33658
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 38 deletions.
14 changes: 7 additions & 7 deletions examples/unix/c11/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@ int main(int argc, char **argv) {
}

printf("Declaring key expression '%s'...\n", keyexpr);
z_owned_keyexpr_t ke = z_declare_keyexpr(z_loan(s), z_keyexpr(keyexpr));
if (!z_check(ke)) {
printf("Unable to declare key expression!\n");
return -1;
}
// z_owned_keyexpr_t ke = z_declare_keyexpr(z_loan(s), z_keyexpr(keyexpr));
// if (!z_check(ke)) {
// printf("Unable to declare key expression!\n");
// return -1;
// }

printf("Putting Data ('%s': '%s')...\n", keyexpr, value);
z_put_options_t options = z_put_options_default();
options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL);
if (z_put(z_loan(s), z_loan(ke), (const uint8_t *)value, strlen(value), &options) < 0) {
if (z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)value, strlen(value), &options) < 0) {
printf("Oh no! Put has failed...\n");
}

z_undeclare_keyexpr(z_loan(s), z_move(ke));
// z_undeclare_keyexpr(z_loan(s), z_move(ke));

// Stop read and lease tasks for zenoh-pico
zp_stop_read_task(z_loan(s));
Expand Down
6 changes: 4 additions & 2 deletions include/zenoh-pico/net/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#ifndef ZENOH_PICO_QUERY_NETAPI_H
#define ZENOH_PICO_QUERY_NETAPI_H

#include <stdint.h>

#include "zenoh-pico/api/constants.h"
#include "zenoh-pico/protocol/core.h"

Expand All @@ -23,7 +25,7 @@
typedef struct {
_z_value_t _value;
_z_keyexpr_t _key;
_z_zint_t _rid;
uint32_t _rid;
void *_zn; // FIXME: _z_session_t *zn;
char *_parameters;
_Bool _anyke;
Expand All @@ -33,7 +35,7 @@ typedef struct {
* Return type when declaring a queryable.
*/
typedef struct {
_z_zint_t _id;
uint32_t _id;
void *_zn; // FIXME: _z_session_t *zn;
} _z_queryable_t;

Expand Down
4 changes: 3 additions & 1 deletion include/zenoh-pico/net/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#ifndef ZENOH_PICO_RESOURCE_NETAPI_H
#define ZENOH_PICO_RESOURCE_NETAPI_H

#include <stdint.h>

#include "zenoh-pico/collections/string.h"
#include "zenoh-pico/protocol/core.h"

Expand All @@ -39,6 +41,6 @@ _z_keyexpr_t _z_rname(const char *rname);
* Returns:
* A :c:type:`_z_keyexpr_t` containing a new resource key.
*/
_z_keyexpr_t _z_rid_with_suffix(_z_zint_t rid, const char *suffix);
_z_keyexpr_t _z_rid_with_suffix(uint16_t rid, const char *suffix);

#endif /* ZENOH_PICO_RESOURCE_NETAPI_H */
4 changes: 3 additions & 1 deletion include/zenoh-pico/net/subscribe.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
#ifndef ZENOH_PICO_SUBSCRIBE_NETAPI_H
#define ZENOH_PICO_SUBSCRIBE_NETAPI_H

#include <stdint.h>

#include "zenoh-pico/net/session.h"
#include "zenoh-pico/protocol/core.h"

/**
* Return type when declaring a subscriber.
*/
typedef struct {
_z_zint_t _id;
uint32_t _id;
_z_session_t *_zn;
} _z_subscriber_t;

Expand Down
12 changes: 3 additions & 9 deletions src/net/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@
#include "zenoh-pico/net/resource.h"

#include <stddef.h>
#include <stdint.h>

#include "zenoh-pico/protocol/core.h"

_z_keyexpr_t _z_rname(const char *rname) {
return (_z_keyexpr_t){
._id = Z_RESOURCE_ID_NONE,
._uses_remote_mapping = false,
._owns_suffix = false,
._suffix = (char *)rname,
};
}
_z_keyexpr_t _z_rname(const char *rname) { return _z_rid_with_suffix(0, rname); }

_z_keyexpr_t _z_rid_with_suffix(_z_zint_t rid, const char *suffix) {
_z_keyexpr_t _z_rid_with_suffix(uint16_t rid, const char *suffix) {
return (_z_keyexpr_t){
._id = rid,
._uses_remote_mapping = false,
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ int8_t _z_zint16_decode(uint16_t *zint, _z_zbuf_t *zbf) {
_z_zint_t buf;
_Z_RETURN_IF_ERR(_z_zint_decode(&buf, zbf));
if (buf <= UINT16_MAX) {
*zint = buf;
*zint = (uint16_t)buf;
} else {
ret = _Z_ERR_MESSAGE_DESERIALIZATION_FAILED;
}
Expand All @@ -250,7 +250,7 @@ int8_t _z_zint32_decode(uint32_t *zint, _z_zbuf_t *zbf) {
_z_zint_t buf;
_Z_RETURN_IF_ERR(_z_zint_decode(&buf, zbf));
if (buf <= UINT32_MAX) {
*zint = buf;
*zint = (uint32_t)buf;
} else {
ret = _Z_ERR_MESSAGE_DESERIALIZATION_FAILED;
}
Expand Down
5 changes: 0 additions & 5 deletions src/protocol/codec/ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ int8_t _z_msg_ext_decode_iter(_z_zbuf_t *zbf, int8_t (*callback)(_z_msg_ext_t *,
_z_msg_ext_t ext = _z_msg_ext_make_unit(0);
size_t start = zbf->_ios._r_pos;
ret |= _z_msg_ext_decode(&ext, zbf, &has_next);
printf("EXT (%d): ", ret);
for (; start < zbf->_ios._r_pos; start++) {
printf("%02x ", zbf->_ios._buf[start]);
}
printf("\n");
if (ret == _Z_RES_OK) {
ret |= callback(&ext, context);
_z_msg_ext_clear(&ext);
Expand Down
6 changes: 3 additions & 3 deletions src/protocol/codec/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ int8_t _z_source_info_decode(_z_source_info_t *info, _z_zbuf_t *zbf) {
if (ret == _Z_RES_OK) {
ret = _z_zint_decode(&intbuf, zbf);
if (intbuf <= UINT32_MAX) {
info->_entity_id = intbuf;
info->_entity_id = (uint32_t)intbuf;
} else {
ret = _Z_ERR_MESSAGE_DESERIALIZATION_FAILED;
}
}
if (ret == _Z_RES_OK) {
ret = _z_zint_decode(&intbuf, zbf);
if (intbuf <= UINT32_MAX) {
info->_source_sn = intbuf;
info->_source_sn = (uint32_t)intbuf;
} else {
ret = _Z_ERR_MESSAGE_DESERIALIZATION_FAILED;
}
Expand Down Expand Up @@ -620,7 +620,7 @@ int8_t _z_err_decode(_z_msg_err_t *err, _z_zbuf_t *zbf, uint8_t header) {
_z_zint_t code;
ret = _z_zint_decode(&code, zbf);
if (code <= UINT16_MAX) {
err->_code = code;
err->_code = (uint16_t)code;
} else {
ret = _Z_ERR_MESSAGE_DESERIALIZATION_FAILED;
}
Expand Down
22 changes: 17 additions & 5 deletions src/protocol/codec/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ int8_t _z_push_decode_ext_cb(_z_msg_ext_t *extension, void *ctx) {
_z_n_msg_push_t *msg = (_z_n_msg_push_t *)ctx;
switch (_Z_EXT_FULL_ID(extension->_header)) {
case _Z_MSG_EXT_ENC_ZINT | 0x01: { // QOS ext
msg->_qos = (_z_n_qos_t){._val = extension->_body._zint._val};
if (extension->_body._zint._val > UINT32_MAX) {
return _Z_ERR_MESSAGE_DESERIALIZATION_FAILED;
}
msg->_qos = (_z_n_qos_t){._val = (uint32_t)extension->_body._zint._val};
break;
}
case _Z_MSG_EXT_ENC_ZBUF | 0x02: { // Timestamp ext
Expand Down Expand Up @@ -167,7 +170,10 @@ int8_t _z_request_decode_extensions(_z_msg_ext_t *extension, void *ctx) {
_z_n_msg_request_t *msg = (_z_n_msg_request_t *)ctx;
switch (_Z_EXT_FULL_ID(extension->_header)) {
case 0x01 | _Z_MSG_EXT_ENC_ZINT: { // QOS ext
msg->_ext_qos = (_z_n_qos_t){._val = extension->_body._zint._val};
if (extension->_body._zint._val > UINT8_MAX) {
return _Z_ERR_MESSAGE_DESERIALIZATION_FAILED;
}
msg->_ext_qos = (_z_n_qos_t){._val = (uint8_t)extension->_body._zint._val};
break;
}
case 0x02 | _Z_MSG_EXT_ENC_ZBUF: { // Timestamp ext
Expand All @@ -176,16 +182,22 @@ int8_t _z_request_decode_extensions(_z_msg_ext_t *extension, void *ctx) {
break;
}
case 0x04 | _Z_MSG_EXT_ENC_ZINT | _Z_MSG_EXT_FLAG_M: {
msg->_ext_target = extension->_body._zint._val;
msg->_ext_target = (uint8_t)extension->_body._zint._val;
if (msg->_ext_target > 2) {
return _Z_ERR_MESSAGE_DESERIALIZATION_FAILED;
}
} break;
case 0x05 | _Z_MSG_EXT_ENC_ZINT: {
msg->_ext_budget = extension->_body._zint._val;
if (extension->_body._zint._val > UINT32_MAX) {
return _Z_ERR_MESSAGE_DESERIALIZATION_FAILED;
}
msg->_ext_budget = (uint32_t)extension->_body._zint._val;
} break;
case 0x06 | _Z_MSG_EXT_ENC_ZINT: {
msg->_ext_timeout_ms = extension->_body._zint._val;
if (extension->_body._zint._val > UINT32_MAX) {
return _Z_ERR_MESSAGE_DESERIALIZATION_FAILED;
}
msg->_ext_timeout_ms = (uint32_t)extension->_body._zint._val;
} break;
default:
if ((extension->_header & _Z_MSG_EXT_FLAG_M) != 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/session/subscription.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ _z_subscription_sptr_list_t *_z_get_subscriptions_by_key(_z_session_t *zn, uint8
}

_z_subscription_sptr_t *_z_register_subscription(_z_session_t *zn, uint8_t is_local, _z_subscription_t *s) {
_Z_DEBUG(">>> Allocating sub decl for (%zu:%s)\n", s->_key._id, s->_key._suffix);
_Z_DEBUG(">>> Allocating sub decl for (%ju:%s)\n", (uintmax_t)s->_key._id, s->_key._suffix);
_z_subscription_sptr_t *ret = NULL;

#if Z_MULTI_THREAD == 1
Expand Down
3 changes: 2 additions & 1 deletion src/system/windows/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// ZettaScale Zenoh Team, <[email protected]>
//

#include <sys/types.h>
#include <windows.h>
// The following includes must come after winsock2
#include <ntsecapi.h>
Expand Down Expand Up @@ -46,7 +47,7 @@ uint64_t z_random_u64(void) {
return ret;
}

void z_random_fill(void *buf, size_t len) { RtlGenRandom(buf, len); }
void z_random_fill(void *buf, size_t len) { RtlGenRandom(buf, (ulong)len); }

/*------------------ Memory ------------------*/
// #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
Expand Down
3 changes: 2 additions & 1 deletion src/utils/uuid.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "zenoh-pico/utils/uuid.h"

#include <stdint.h>
#include <stdlib.h>

#include "zenoh-pico/utils/pointers.h"
Expand All @@ -27,7 +28,7 @@ void _z_uuid_to_bytes(uint8_t *bytes, const char *uuid_str) {
n_dash += 1;
}
char val[5] = {'0', 'x', uuid_str[i + n_dash], uuid_str[i + 1 + n_dash], '\0'};
*bytes = strtol(val, NULL, 0);
*bytes = (uint8_t)strtoul(val, NULL, 0);
bytes = _z_ptr_u8_offset(bytes, 1);
}
}
10 changes: 10 additions & 0 deletions tests/z_msgcodec_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
#define _Z_MOCK_EXTENSION_ZINT 0x02
#define _Z_MOCK_EXTENSION_ZBUF 0x03

#if defined(_WIN32) || defined(WIN32)
#pragma warning(push)
#pragma warning(disable : 4244 4267) // Disable truncation warnings in MSVC,
// as it is used voluntarily in this file when working with RNG
#endif

/*=============================*/
/* Helper functions */
/*=============================*/
Expand Down Expand Up @@ -1870,3 +1876,7 @@ int main(void) {

return 0;
}

#if defined(_WIN32) || defined(WIN32)
#pragma warning(pop)
#endif

0 comments on commit 5a33658

Please sign in to comment.