diff --git a/CMakeLists.txt b/CMakeLists.txt index 69ac6dc24..2c32d9bb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,6 +178,8 @@ endif() if(CMAKE_BUILD_TYPE MATCHES "DEBUG") if(UNIX) add_compile_options(-c -Wall -Wextra -Werror -Wshadow -Wpedantic -Wunused -Wstrict-prototypes -pipe -g -O0) + # add_compile_options(-Wconversion) + # add_link_options(-fsanitize=address) elseif(MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c11 /experimental:c11atomics") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++latest /experimental:c11atomics") diff --git a/examples/freertos_plus_tcp/z_get.c b/examples/freertos_plus_tcp/z_get.c index 39545dc2a..6abd0175e 100644 --- a/examples/freertos_plus_tcp/z_get.c +++ b/examples/freertos_plus_tcp/z_get.c @@ -65,6 +65,7 @@ void app_main(void) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return; } diff --git a/examples/freertos_plus_tcp/z_pub.c b/examples/freertos_plus_tcp/z_pub.c index a71557045..c2d8ca55b 100644 --- a/examples/freertos_plus_tcp/z_pub.c +++ b/examples/freertos_plus_tcp/z_pub.c @@ -76,6 +76,7 @@ void app_main(void) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), &read_task_opt) < 0 || zp_start_lease_task(z_loan(s), &lease_task_opt) < 0) { printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return; } diff --git a/examples/freertos_plus_tcp/z_pull.c b/examples/freertos_plus_tcp/z_pull.c index 04d2c3e34..b8f5c5ee8 100644 --- a/examples/freertos_plus_tcp/z_pull.c +++ b/examples/freertos_plus_tcp/z_pull.c @@ -53,6 +53,7 @@ void app_main(void) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return; } diff --git a/examples/freertos_plus_tcp/z_put.c b/examples/freertos_plus_tcp/z_put.c index 40b142645..898d0e9b8 100644 --- a/examples/freertos_plus_tcp/z_put.c +++ b/examples/freertos_plus_tcp/z_put.c @@ -46,6 +46,7 @@ void app_main(void) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return; } @@ -53,6 +54,9 @@ void app_main(void) { 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"); + zp_stop_read_task(z_loan(s)); + zp_stop_lease_task(z_loan(s)); + z_close(z_move(s)); return; } @@ -67,12 +71,10 @@ void app_main(void) { zp_sleep_s(1); } + // Clean up z_undeclare_keyexpr(z_loan(s), z_move(ke)); - - // Stop read and lease tasks for zenoh-pico zp_stop_read_task(z_loan(s)); zp_stop_lease_task(z_loan(s)); - z_close(z_move(s)); } #else diff --git a/examples/freertos_plus_tcp/z_queryable.c b/examples/freertos_plus_tcp/z_queryable.c index ea46660d1..0d9ce87e4 100644 --- a/examples/freertos_plus_tcp/z_queryable.c +++ b/examples/freertos_plus_tcp/z_queryable.c @@ -61,6 +61,7 @@ void app_main(void) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return; } diff --git a/examples/freertos_plus_tcp/z_sub.c b/examples/freertos_plus_tcp/z_sub.c index ce4a90b1a..91395e59f 100644 --- a/examples/freertos_plus_tcp/z_sub.c +++ b/examples/freertos_plus_tcp/z_sub.c @@ -53,6 +53,7 @@ void app_main(void) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return; } diff --git a/examples/unix/c11/z_get.c b/examples/unix/c11/z_get.c index e2aa07e9c..ca45ec493 100644 --- a/examples/unix/c11/z_get.c +++ b/examples/unix/c11/z_get.c @@ -91,7 +91,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/unix/c11/z_info.c b/examples/unix/c11/z_info.c index 2740d5110..455fe17c7 100644 --- a/examples/unix/c11/z_info.c +++ b/examples/unix/c11/z_info.c @@ -74,7 +74,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/unix/c11/z_ping.c b/examples/unix/c11/z_ping.c index 65a871f05..564cbc365 100644 --- a/examples/unix/c11/z_ping.c +++ b/examples/unix/c11/z_ping.c @@ -71,7 +71,8 @@ int main(int argc, char** argv) { } if (zp_start_read_task(z_loan(session), NULL) < 0 || zp_start_lease_task(z_loan(session), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&session)); return -1; } @@ -93,7 +94,7 @@ int main(int argc, char** argv) { uint8_t* data = zp_malloc(args.size); for (unsigned int i = 0; i < args.size; i++) { - data[i] = i % 10; + data[i] = (uint8_t)(i % 10); } zp_mutex_lock(&mutex); if (args.warmup_ms) { @@ -151,17 +152,17 @@ struct args_t parse_args(int argc, char** argv) { char* arg = getopt(argc, argv, 's'); unsigned int size = DEFAULT_PKT_SIZE; if (arg) { - size = atoi(arg); + size = (unsigned int)atoi(arg); } arg = getopt(argc, argv, 'n'); unsigned int number_of_pings = DEFAULT_PING_NB; if (arg) { - number_of_pings = atoi(arg); + number_of_pings = (unsigned int)atoi(arg); } arg = getopt(argc, argv, 'w'); unsigned int warmup_ms = DEFAULT_WARMUP_MS; if (arg) { - warmup_ms = atoi(arg); + warmup_ms = (unsigned int)atoi(arg); } return (struct args_t){ .help_requested = 0, diff --git a/examples/unix/c11/z_pong.c b/examples/unix/c11/z_pong.c index 8991729e9..dc958e1bb 100644 --- a/examples/unix/c11/z_pong.c +++ b/examples/unix/c11/z_pong.c @@ -40,7 +40,8 @@ int main(int argc, char** argv) { } if (zp_start_read_task(z_loan(session), NULL) < 0 || zp_start_lease_task(z_loan(session), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&session)); return -1; } diff --git a/examples/unix/c11/z_pub.c b/examples/unix/c11/z_pub.c index 2d0ea81ac..064b53677 100644 --- a/examples/unix/c11/z_pub.c +++ b/examples/unix/c11/z_pub.c @@ -84,7 +84,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/unix/c11/z_pub_thr.c b/examples/unix/c11/z_pub_thr.c index d1379c43c..9711ed46c 100644 --- a/examples/unix/c11/z_pub_thr.c +++ b/examples/unix/c11/z_pub_thr.c @@ -25,7 +25,7 @@ int main(int argc, char **argv) { exit(-1); } char *keyexpr = "test/thr"; - size_t len = atoi(argv[1]); + size_t len = (size_t)atoi(argv[1]); uint8_t *value = (uint8_t *)malloc(len); memset(value, 1, len); @@ -45,7 +45,8 @@ int main(int argc, char **argv) { } // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); exit(-1); } // Declare publisher diff --git a/examples/unix/c11/z_pull.c b/examples/unix/c11/z_pull.c index c39f19c52..c6f710bfb 100644 --- a/examples/unix/c11/z_pull.c +++ b/examples/unix/c11/z_pull.c @@ -66,7 +66,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/unix/c11/z_put.c b/examples/unix/c11/z_put.c index a542c26ac..19c6b051a 100644 --- a/examples/unix/c11/z_put.c +++ b/examples/unix/c11/z_put.c @@ -79,16 +79,20 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } 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"); + zp_stop_read_task(z_loan(s)); + zp_stop_lease_task(z_loan(s)); + z_close(z_move(s)); + return -1; + } printf("Putting Data ('%s': '%s')...\n", keyexpr, value); z_put_options_t options = z_put_options_default(); @@ -105,9 +109,9 @@ int main(int argc, char **argv) { #if Z_FEATURE_ATTACHMENT == 1 z_bytes_map_drop(&map); #endif - // z_undeclare_keyexpr(z_loan(s), z_move(ke)); - // Stop read and lease tasks for zenoh-pico + // Clean up + z_undeclare_keyexpr(z_loan(s), z_move(ke)); zp_stop_read_task(z_loan(s)); zp_stop_lease_task(z_loan(s)); z_close(z_move(s)); diff --git a/examples/unix/c11/z_queryable.c b/examples/unix/c11/z_queryable.c index d9bb7c74a..e9d1b95e5 100644 --- a/examples/unix/c11/z_queryable.c +++ b/examples/unix/c11/z_queryable.c @@ -90,7 +90,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/unix/c11/z_sub.c b/examples/unix/c11/z_sub.c index 99ea3e1d7..e35fc1427 100644 --- a/examples/unix/c11/z_sub.c +++ b/examples/unix/c11/z_sub.c @@ -95,7 +95,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/unix/c11/z_sub_thr.c b/examples/unix/c11/z_sub_thr.c index 347a70848..39e3e894a 100644 --- a/examples/unix/c11/z_sub_thr.c +++ b/examples/unix/c11/z_sub_thr.c @@ -86,7 +86,8 @@ int main(int argc, char **argv) { } // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); exit(-1); } // Declare Subscriber/resource @@ -101,7 +102,7 @@ int main(int argc, char **argv) { printf("Start listening.\n"); char c = 0; while (c != 'q') { - c = fgetc(stdin); + c = (char)fgetc(stdin); } // Wait for everything to settle printf("End of test\n"); diff --git a/examples/unix/c99/z_get.c b/examples/unix/c99/z_get.c index 29f844879..46121e59e 100644 --- a/examples/unix/c99/z_get.c +++ b/examples/unix/c99/z_get.c @@ -91,7 +91,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_session_loan(&s), NULL) < 0 || zp_start_lease_task(z_session_loan(&s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/unix/c99/z_info.c b/examples/unix/c99/z_info.c index 60606c73a..c978af3b4 100644 --- a/examples/unix/c99/z_info.c +++ b/examples/unix/c99/z_info.c @@ -74,7 +74,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_session_loan(&s), NULL) < 0 || zp_start_lease_task(z_session_loan(&s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/unix/c99/z_ping.c b/examples/unix/c99/z_ping.c index 0ab80b8ba..3bcafece7 100644 --- a/examples/unix/c99/z_ping.c +++ b/examples/unix/c99/z_ping.c @@ -73,7 +73,8 @@ int main(int argc, char** argv) { if (zp_start_read_task(z_session_loan(&session), NULL) < 0 || zp_start_lease_task(z_session_loan(&session), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&session)); return -1; } @@ -95,7 +96,7 @@ int main(int argc, char** argv) { uint8_t* data = zp_malloc(args.size); for (unsigned int i = 0; i < args.size; i++) { - data[i] = i % 10; + data[i] = (uint8_t)(i % 10); } zp_mutex_lock(&mutex); if (args.warmup_ms) { @@ -153,17 +154,17 @@ struct args_t parse_args(int argc, char** argv) { char* arg = getopt(argc, argv, 's'); unsigned int size = DEFAULT_PKT_SIZE; if (arg) { - size = atoi(arg); + size = (unsigned int)atoi(arg); } arg = getopt(argc, argv, 'n'); unsigned int number_of_pings = DEFAULT_PING_NB; if (arg) { - number_of_pings = atoi(arg); + number_of_pings = (unsigned int)atoi(arg); } arg = getopt(argc, argv, 'w'); unsigned int warmup_ms = DEFAULT_WARMUP_MS; if (arg) { - warmup_ms = atoi(arg); + warmup_ms = (unsigned int)atoi(arg); } return (struct args_t){ .help_requested = 0, diff --git a/examples/unix/c99/z_pong.c b/examples/unix/c99/z_pong.c index 73570e138..73f93d9a1 100644 --- a/examples/unix/c99/z_pong.c +++ b/examples/unix/c99/z_pong.c @@ -42,7 +42,8 @@ int main(int argc, char** argv) { if (zp_start_read_task(z_session_loan(&session), NULL) < 0 || zp_start_lease_task(z_session_loan(&session), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&session)); return -1; } diff --git a/examples/unix/c99/z_pub.c b/examples/unix/c99/z_pub.c index f617c7741..36483fae3 100644 --- a/examples/unix/c99/z_pub.c +++ b/examples/unix/c99/z_pub.c @@ -26,9 +26,10 @@ int main(int argc, char **argv) { const char *mode = "client"; char *clocator = NULL; char *llocator = NULL; + int n = 10; int opt; - while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) { + while ((opt = getopt(argc, argv, "k:v:e:m:l:n:")) != -1) { switch (opt) { case 'k': keyexpr = optarg; @@ -45,8 +46,12 @@ int main(int argc, char **argv) { case 'l': llocator = optarg; break; + case 'n': + n = atoi(optarg); + break; case '?': - if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') { + if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l' || + optopt == 'n') { fprintf(stderr, "Option -%c requires an argument.\n", optopt); } else { fprintf(stderr, "Unknown option `-%c'.\n", optopt); @@ -75,7 +80,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_session_loan(&s), NULL) < 0 || zp_start_lease_task(z_session_loan(&s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } @@ -86,25 +92,20 @@ int main(int argc, char **argv) { return -1; } - char *buf = (char *)malloc(256); - for (int idx = 0; 1; ++idx) { + for (int idx = 0; idx < n; ++idx) { sleep(1); - snprintf(buf, 256, "[%4d] %s", idx, value); - printf("Putting Data ('%s': '%s')...\n", keyexpr, buf); + (void)idx; + printf("Putting Data ('%s': '%s')...\n", keyexpr, value); + z_publisher_put_options_t options = z_publisher_put_options_default(); options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); - z_publisher_put(z_publisher_loan(&pub), (const uint8_t *)buf, strlen(buf), &options); + z_publisher_put(z_publisher_loan(&pub), (const uint8_t *)value, strlen(value), &options); } - + // Clean up z_undeclare_publisher(z_publisher_move(&pub)); - - // Stop read and lease tasks for zenoh-pico zp_stop_read_task(z_session_loan(&s)); zp_stop_lease_task(z_session_loan(&s)); - z_close(z_session_move(&s)); - - free(buf); return 0; } #else diff --git a/examples/unix/c99/z_pull.c b/examples/unix/c99/z_pull.c index 10c16d462..efe2ba8bf 100644 --- a/examples/unix/c99/z_pull.c +++ b/examples/unix/c99/z_pull.c @@ -66,7 +66,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_session_loan(&s), NULL) < 0 || zp_start_lease_task(z_session_loan(&s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/unix/c99/z_put.c b/examples/unix/c99/z_put.c index 82c259426..453444869 100644 --- a/examples/unix/c99/z_put.c +++ b/examples/unix/c99/z_put.c @@ -75,7 +75,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_session_loan(&s), NULL) < 0 || zp_start_lease_task(z_session_loan(&s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } @@ -83,6 +84,9 @@ int main(int argc, char **argv) { z_owned_keyexpr_t ke = z_declare_keyexpr(z_session_loan(&s), z_keyexpr(keyexpr)); if (!z_keyexpr_check(&ke)) { printf("Unable to declare key expression!\n"); + zp_stop_read_task(z_session_loan(&s)); + zp_stop_lease_task(z_session_loan(&s)); + z_close(z_session_move(&s)); return -1; } @@ -93,12 +97,10 @@ int main(int argc, char **argv) { printf("Oh no! Put has failed...\n"); } + // Clean up z_undeclare_keyexpr(z_session_loan(&s), z_keyexpr_move(&ke)); - - // Stop read and lease tasks for zenoh-pico zp_stop_read_task(z_session_loan(&s)); zp_stop_lease_task(z_session_loan(&s)); - z_close(z_session_move(&s)); return 0; } diff --git a/examples/unix/c99/z_queryable.c b/examples/unix/c99/z_queryable.c index a7c2d28af..8460aef16 100644 --- a/examples/unix/c99/z_queryable.c +++ b/examples/unix/c99/z_queryable.c @@ -86,7 +86,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_session_loan(&s), NULL) < 0 || zp_start_lease_task(z_session_loan(&s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/unix/c99/z_sub.c b/examples/unix/c99/z_sub.c index 88c144889..8d25dbb74 100644 --- a/examples/unix/c99/z_sub.c +++ b/examples/unix/c99/z_sub.c @@ -79,7 +79,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_session_loan(&s), NULL) < 0 || zp_start_lease_task(z_session_loan(&s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/windows/z_get.c b/examples/windows/z_get.c index 5d2676ffc..2815656dc 100644 --- a/examples/windows/z_get.c +++ b/examples/windows/z_get.c @@ -56,7 +56,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/windows/z_info.c b/examples/windows/z_info.c index eed2c2952..7967e1aa2 100644 --- a/examples/windows/z_info.c +++ b/examples/windows/z_info.c @@ -47,7 +47,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/windows/z_ping.c b/examples/windows/z_ping.c index e260f5459..5643832c0 100644 --- a/examples/windows/z_ping.c +++ b/examples/windows/z_ping.c @@ -71,7 +71,8 @@ int main(int argc, char** argv) { } if (zp_start_read_task(z_loan(session), NULL) < 0 || zp_start_lease_task(z_loan(session), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&session)); return -1; } diff --git a/examples/windows/z_pong.c b/examples/windows/z_pong.c index 8991729e9..dc958e1bb 100644 --- a/examples/windows/z_pong.c +++ b/examples/windows/z_pong.c @@ -40,7 +40,8 @@ int main(int argc, char** argv) { } if (zp_start_read_task(z_loan(session), NULL) < 0 || zp_start_lease_task(z_loan(session), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&session)); return -1; } diff --git a/examples/windows/z_pub.c b/examples/windows/z_pub.c index 89c542ad4..8c17d7f7d 100644 --- a/examples/windows/z_pub.c +++ b/examples/windows/z_pub.c @@ -42,7 +42,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/windows/z_pull.c b/examples/windows/z_pull.c index 4480a43d0..512b2bb79 100644 --- a/examples/windows/z_pull.c +++ b/examples/windows/z_pull.c @@ -46,7 +46,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/windows/z_put.c b/examples/windows/z_put.c index 29febb7a2..32f7802a7 100644 --- a/examples/windows/z_put.c +++ b/examples/windows/z_put.c @@ -42,7 +42,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } @@ -50,6 +51,9 @@ int main(int argc, char **argv) { 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"); + zp_stop_read_task(z_loan(s)); + zp_stop_lease_task(z_loan(s)); + z_close(z_move(s)); return -1; } @@ -60,12 +64,10 @@ int main(int argc, char **argv) { printf("Oh no! Put has failed...\n"); } + // Clean up z_undeclare_keyexpr(z_loan(s), z_move(ke)); - - // Stop read and lease tasks for zenoh-pico zp_stop_read_task(z_loan(s)); zp_stop_lease_task(z_loan(s)); - z_close(z_move(s)); return 0; } diff --git a/examples/windows/z_queryable.c b/examples/windows/z_queryable.c index d010ce3fa..7a2d7771c 100644 --- a/examples/windows/z_queryable.c +++ b/examples/windows/z_queryable.c @@ -55,7 +55,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/examples/windows/z_sub.c b/examples/windows/z_sub.c index 57cd8f13f..0ffd26568 100644 --- a/examples/windows/z_sub.c +++ b/examples/windows/z_sub.c @@ -49,7 +49,8 @@ int main(int argc, char **argv) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/src/protocol/codec/transport.c b/src/protocol/codec/transport.c index e830cb7e6..1eaf27a41 100644 --- a/src/protocol/codec/transport.c +++ b/src/protocol/codec/transport.c @@ -351,6 +351,7 @@ int8_t _z_frame_decode(_z_t_msg_frame_t *msg, _z_zbuf_t *zbf, uint8_t header) { // Mark the reading position of the iobfer size_t r_pos = _z_zbuf_get_rpos(zbf); _z_network_message_t *nm = (_z_network_message_t *)zp_malloc(sizeof(_z_network_message_t)); + memset(nm, 0, sizeof(_z_network_message_t)); ret |= _z_network_message_decode(nm, zbf); if (ret == _Z_RES_OK) { _z_network_message_vec_append(&msg->_messages, nm); diff --git a/tests/z_iobuf_test.c b/tests/z_iobuf_test.c index 1a49129dc..88fe777b7 100644 --- a/tests/z_iobuf_test.c +++ b/tests/z_iobuf_test.c @@ -265,7 +265,7 @@ void zbuf_compact(void) { assert(_z_zbuf_len(&zbf) == len01); printf(" Len: %zu, Rpos: %zu, Wpos: %zu\n", len01, _z_zbuf_get_rpos(&zbf), _z_zbuf_get_wpos(&zbf)); - uint8_t vs = 1 + gen_uint8() % (len - counter); + uint8_t vs = (uint8_t)(1 + gen_uint8() % (len - counter)); printf(" Read %u bytes => [", vs); for (uint8_t i = 0; i < vs; i++) { uint8_t l = counter++; @@ -291,7 +291,7 @@ void zbuf_view(void) { uint8_t counter = 0; while (counter < len) { - uint8_t vs = 1 + gen_uint8() % (len - counter); + uint8_t vs = (uint8_t)(1 + gen_uint8() % (len - counter)); _z_zbuf_t rv = _z_zbuf_view(&zbf, vs); printf(" View of %u bytes: ", vs); @@ -448,7 +448,7 @@ void wbuf_reusable_write_zbuf_read(void) { printf(" Writing %zu bytes\n", len); for (size_t z = 0; z < len; z++) { size_t prev_len = _z_wbuf_len(&wbf); - assert(_z_wbuf_write(&wbf, z % (uint8_t)255) == 0); + assert(_z_wbuf_write(&wbf, (uint8_t)(z % 255)) == 0); assert(_z_wbuf_len(&wbf) == prev_len + 1); } diff --git a/tests/z_msgcodec_test.c b/tests/z_msgcodec_test.c index 1bc1bdc3a..4e4511baa 100644 --- a/tests/z_msgcodec_test.c +++ b/tests/z_msgcodec_test.c @@ -137,7 +137,7 @@ _Bool gen_bool(void) { return zp_random_u8() % 2; } uint8_t gen_uint8(void) { return zp_random_u8(); } -uint8_t gen_uint16(void) { return zp_random_u16(); } +uint16_t gen_uint16(void) { return zp_random_u16(); } uint64_t gen_uint64(void) { uint64_t ret = 0; @@ -496,7 +496,8 @@ void payload_field(void) { } _z_source_info_t gen_source_info(void) { - return (_z_source_info_t){._id = gen_zid(), ._source_sn = gen_uint64(), ._entity_id = gen_uint64()}; + return (_z_source_info_t){ + ._id = gen_zid(), ._source_sn = (uint32_t)gen_uint64(), ._entity_id = (uint32_t)gen_uint64()}; } void assert_eq_source_info(const _z_source_info_t *left, const _z_source_info_t *right) { @@ -607,7 +608,7 @@ void assert_eq_subinfo(_z_subinfo_t *left, _z_subinfo_t *right) { /*------------------ ResKey field ------------------*/ _z_keyexpr_t gen_keyexpr(void) { _z_keyexpr_t key; - key._id = gen_zint(); + key._id = gen_uint16(); key._mapping._val = gen_uint8(); _Bool is_numerical = gen_bool(); if (is_numerical == true) { @@ -671,7 +672,7 @@ void keyexpr_field(void) { /*=============================*/ /*------------------ Resource declaration ------------------*/ _z_decl_kexpr_t gen_resource_declaration(void) { - return (_z_decl_kexpr_t){._id = gen_zint(), ._keyexpr = gen_keyexpr()}; + return (_z_decl_kexpr_t){._id = gen_uint16(), ._keyexpr = gen_keyexpr()}; } void assert_eq_resource_declaration(const _z_decl_kexpr_t *left, const _z_decl_kexpr_t *right) { @@ -715,7 +716,7 @@ void resource_declaration(void) { _z_decl_subscriber_t gen_subscriber_declaration(void) { _z_subinfo_t subinfo = gen_subinfo(); _z_decl_subscriber_t e_sd = {._keyexpr = gen_keyexpr(), - ._id = gen_uint64(), + ._id = (uint32_t)gen_uint64(), ._ext_subinfo = {._pull_mode = subinfo.mode == Z_SUBMODE_PULL, ._reliable = subinfo.reliability == Z_RELIABILITY_RELIABLE}}; return e_sd; @@ -761,8 +762,8 @@ void subscriber_declaration(void) { /*------------------ Queryable declaration ------------------*/ _z_decl_queryable_t gen_queryable_declaration(void) { _z_decl_queryable_t e_qd = {._keyexpr = gen_keyexpr(), - ._id = gen_uint64(), - ._ext_queryable_info = {._complete = gen_zint(), ._distance = gen_zint()}}; + ._id = (uint32_t)gen_uint64(), + ._ext_queryable_info = {._complete = gen_uint8(), ._distance = (uint32_t)gen_zint()}}; return e_qd; } @@ -811,7 +812,7 @@ void queryable_declaration(void) { _z_undecl_kexpr_t gen_forget_resource_declaration(void) { _z_undecl_kexpr_t e_frd; - e_frd._id = gen_zint(); + e_frd._id = gen_uint16(); return e_frd; } @@ -853,7 +854,7 @@ void forget_resource_declaration(void) { /*------------------ Forget Subscriber declaration ------------------*/ _z_undecl_subscriber_t gen_forget_subscriber_declaration(void) { - _z_undecl_subscriber_t e_fsd = {._ext_keyexpr = gen_keyexpr(), ._id = gen_uint64()}; + _z_undecl_subscriber_t e_fsd = {._ext_keyexpr = gen_keyexpr(), ._id = (uint32_t)gen_uint64()}; return e_fsd; } @@ -895,7 +896,7 @@ void forget_subscriber_declaration(void) { /*------------------ Forget Queryable declaration ------------------*/ _z_undecl_queryable_t gen_forget_queryable_declaration(void) { - _z_undecl_queryable_t e_fqd = {._ext_keyexpr = gen_keyexpr(), ._id = gen_zint()}; + _z_undecl_queryable_t e_fqd = {._ext_keyexpr = gen_keyexpr(), ._id = (uint32_t)gen_zint()}; return e_fqd; } @@ -1293,8 +1294,8 @@ _z_n_msg_request_t gen_request(void) { ._ext_qos = gen_bool() ? _z_n_qos_make(gen_bool(), gen_bool(), gen_uint8() % 8) : _Z_N_QOS_DEFAULT, ._ext_timestamp = gen_bool() ? gen_timestamp() : _z_timestamp_null(), ._ext_target = gen_uint8() % 3, - ._ext_budget = gen_bool() ? gen_uint64() : 0, - ._ext_timeout_ms = gen_bool() ? gen_uint64() : 0, + ._ext_budget = gen_bool() ? (uint32_t)gen_uint64() : 0, + ._ext_timeout_ms = gen_bool() ? (uint32_t)gen_uint64() : 0, }; switch (gen_uint8() % 4) { case 0: { @@ -1574,7 +1575,7 @@ void open_message(void) { _z_wbuf_clear(&wbf); } -_z_transport_message_t gen_close(void) { return _z_t_msg_make_close(gen_uint(), gen_bool()); } +_z_transport_message_t gen_close(void) { return _z_t_msg_make_close(gen_uint8(), gen_bool()); } void assert_eq_close(const _z_t_msg_close_t *left, const _z_t_msg_close_t *right) { assert(left->_reason == right->_reason); } diff --git a/tests/z_perf_rx.c b/tests/z_perf_rx.c index 47ebb5cb0..2eadf731c 100644 --- a/tests/z_perf_rx.c +++ b/tests/z_perf_rx.c @@ -92,7 +92,8 @@ int main(int argc, char **argv) { } // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); exit(-1); } // Declare Subscriber/resource diff --git a/tests/z_perf_tx.c b/tests/z_perf_tx.c index d9e5e7777..168294d28 100644 --- a/tests/z_perf_tx.c +++ b/tests/z_perf_tx.c @@ -70,7 +70,8 @@ int main(int argc, char **argv) { } // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); exit(-1); } // Declare publisher diff --git a/tests/z_session_test.c b/tests/z_session_test.c index c7afabec1..33b1977bc 100644 --- a/tests/z_session_test.c +++ b/tests/z_session_test.c @@ -34,7 +34,8 @@ int main(void) { // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } diff --git a/tests/z_test_fragment_rx.c b/tests/z_test_fragment_rx.c index b236b1cfc..133497694 100644 --- a/tests/z_test_fragment_rx.c +++ b/tests/z_test_fragment_rx.c @@ -58,7 +58,8 @@ int main(int argc, char **argv) { } // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } // Declare subscriber diff --git a/tests/z_test_fragment_tx.c b/tests/z_test_fragment_tx.c index bec1c673d..b002a34d8 100644 --- a/tests/z_test_fragment_tx.c +++ b/tests/z_test_fragment_tx.c @@ -53,7 +53,8 @@ int main(int argc, char **argv) { } // Start read and lease tasks for zenoh-pico if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) { - printf("Unable to start read and lease tasks"); + printf("Unable to start read and lease tasks\n"); + z_close(z_session_move(&s)); return -1; } // Put data