diff --git a/include/nng/supplemental/nanolib/conf.h b/include/nng/supplemental/nanolib/conf.h index 925847760..74413f559 100644 --- a/include/nng/supplemental/nanolib/conf.h +++ b/include/nng/supplemental/nanolib/conf.h @@ -352,8 +352,8 @@ typedef enum { struct conf_parquet_encryption { bool enable; - const char *key_id; - const char *key; + char *key_id; + char *key; cipher_type type; }; diff --git a/include/nng/supplemental/nanolib/log.h b/include/nng/supplemental/nanolib/log.h index 9da8e20c6..2800c6b44 100644 --- a/include/nng/supplemental/nanolib/log.h +++ b/include/nng/supplemental/nanolib/log.h @@ -94,7 +94,6 @@ NNG_DECL void log_clear_callback(); #define log_warn(...) #define log_error(...) #define log_fatal(...) - #endif @@ -102,4 +101,4 @@ NNG_DECL void log_clear_callback(); } #endif -#endif \ No newline at end of file +#endif diff --git a/src/core/platform.h b/src/core/platform.h index 6d5565b19..03ac3abcf 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -447,7 +447,7 @@ extern int nni_plat_udp_sockname(nni_plat_udp *, nni_sockaddr *); // in APIs to transport file descriptors, or across a fork/exec boundary (so // that child processes may use these with socket to inherit a socket that is // connected to the parent.) -extern int nni_socket_pair(int *); +extern int nni_socket_pair(int [2]); // // File/Store Support diff --git a/src/core/socket.c b/src/core/socket.c index b5d911ea9..e44725fdc 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -674,7 +674,7 @@ nni_sock_replace(nni_sock *sock, nni_sock *new) { nni_ctx *ctx; nni_ctx *nctx; - size_t sz; + size_t sz = 0; nni_mtx_lock(&sock_lk); diff --git a/src/mqtt/protocol/exchange/exchange_server.c b/src/mqtt/protocol/exchange/exchange_server.c index 4c329d17a..38bf3018c 100644 --- a/src/mqtt/protocol/exchange/exchange_server.c +++ b/src/mqtt/protocol/exchange/exchange_server.c @@ -532,6 +532,7 @@ exchange_client_get_msgs_fuzz(void *arg, uint64_t start, uint64_t end, uint32_t return 0; } +#ifdef SUPP_PARQUET static char * get_file_bname(char *fpath) { @@ -552,7 +553,6 @@ get_file_bname(char *fpath) return bname; } -#ifdef SUPP_PARQUET static int get_parquet_files_raw(uint32_t sz, char **fnames, char ***file_raws) { @@ -697,7 +697,6 @@ decToHex(unsigned char decimal, char *hexadecimal) static int fuzz_search_result_cat(nng_msg **msgList, uint32_t count, cJSON *obj) { - char *buf = NULL; uint32_t sz = 0; uint32_t pos = 0; uint32_t diff = 0; @@ -724,7 +723,7 @@ fuzz_search_result_cat(nng_msg **msgList, uint32_t count, cJSON *obj) log_warn("Failed to allocate memory for file payload\n"); return -1; } - for (int j = 0; j < diff; ++j) { + for (uint32_t j = 0; j < diff; ++j) { char *tmpch = (char *)nng_msg_payload_ptr(msgList[i]); char hex[2]; hex[0] = '0'; @@ -742,13 +741,13 @@ fuzz_search_result_cat(nng_msg **msgList, uint32_t count, cJSON *obj) pos += diff; } - cJSON *mqs_obj = cJSON_CreateStringArray(mqdata, count); + cJSON *mqs_obj = cJSON_CreateStringArray((const char * const*)mqdata, count); if (!mqs_obj) { return -1; } cJSON_AddItemToObject(obj, "mq", mqs_obj); - for (int i = 0; i < count; ++i) { + for (uint32_t i = 0; i < count; ++i) { nng_free(mqdata[i], 0); } nng_free(mqdata, sizeof(char *) * count); @@ -766,7 +765,6 @@ ex_query_recv_cb(void *arg) exchange_sock_t *sock = p->sock; nni_msg *msg; - size_t len; uint8_t *body; nni_msg *tar_msg = NULL; int ret; @@ -781,7 +779,6 @@ ex_query_recv_cb(void *arg) nni_msg_set_pipe(msg, nni_pipe_id(p->pipe)); body = nni_msg_body(msg); - len = nni_msg_len(msg); nni_mtx_lock(&sock->mtx); @@ -819,11 +816,11 @@ ex_query_recv_cb(void *arg) return; } for (uint32_t j = 0; j < diff; ++j) { - char *tmpch = nng_msg_payload_ptr(tar_msg); + char *tmpch = (char *)nng_msg_payload_ptr(tar_msg); if (j == 0) { - sprintf(mqdata, "%02x", tmpch[j] & 0xff); + sprintf(mqdata, "%02x", (unsigned char)(tmpch[j] & 0xff)); } else { - sprintf(mqdata, "%s%02x", mqdata, tmpch[j] & 0xff); + sprintf(mqdata, "%s%02x", mqdata, (unsigned char)(tmpch[j] & 0xff)); } } cJSON *mqs_obj = cJSON_CreateString(mqdata); @@ -912,6 +909,8 @@ ex_query_send_cb(void *arg) { exchange_pipe_t *p = arg; exchange_sock_t *sock = p->sock; + + NNI_ARG_UNUSED(sock); } static int diff --git a/src/mqtt/protocol/exchange/exchange_server_test.c b/src/mqtt/protocol/exchange/exchange_server_test.c index ffc2e8cba..a9329ce90 100644 --- a/src/mqtt/protocol/exchange/exchange_server_test.c +++ b/src/mqtt/protocol/exchange/exchange_server_test.c @@ -8,9 +8,9 @@ #define UNUSED(x) ((void) x) -static inline void free_msg_list(nng_msg **msgList, nng_msg *msg, int *lenp, int freeMsg) +static inline void free_msg_list(nng_msg **msgList, nng_msg *msg, uint32_t *lenp, int freeMsg) { - for (int i = 0; i < *lenp; i++) { + for (uint32_t i = 0; i < *lenp; i++) { if (freeMsg) { nng_msg_free(msgList[i]); } @@ -23,11 +23,11 @@ static inline void free_msg_list(nng_msg **msgList, nng_msg *msg, int *lenp, int nng_free(msgList, sizeof(nng_msg *) * (*lenp)); } if (lenp != NULL) { - nng_free(lenp, sizeof(int)); + nng_free(lenp, sizeof(uint32_t)); } } -static inline void client_get_msgs(nng_socket sock, uint64_t startKey, uint64_t endKey, int *lenp, nng_msg ***msgList) +static inline void client_get_msgs(nng_socket sock, uint64_t startKey, uint64_t endKey, uint32_t *lenp, nng_msg ***msgList) { nni_aio *aio = NULL; NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL)); @@ -92,7 +92,7 @@ client_publish(nng_socket sock, const char *topic, uint64_t key, uint8_t *payloa nng_send_aio(sock, aio); nng_aio_wait(aio); - int *lenp = NULL; + uint32_t *lenp = NULL; nng_msg **msgList = (nng_msg **)nng_aio_get_prov_data(aio); nng_msg *msg = nng_aio_get_msg(aio); if (msgList != NULL && msg != NULL) { @@ -144,17 +144,17 @@ test_exchange_client(void) rv = exchange_client_get_msg_by_key(nni_sock_proto_data(nsock), key, &msg); NUTS_TRUE(rv == 0 && msg != NULL); - int *lenp; + uint32_t *lenp; nng_msg **msgList = NULL; rv = exchange_client_get_msgs_by_key(nni_sock_proto_data(nsock), key, 1, &msgList); NUTS_TRUE(rv == 0 && msgList != NULL); - lenp = nng_alloc(sizeof(int)); + lenp = nng_alloc(sizeof(uint32_t)); *lenp = 1; free_msg_list(msgList, NULL, lenp, 0); msgList = NULL; /* Use aio recv to get msgs by key */ - lenp = nng_alloc(sizeof(int)); + lenp = nng_alloc(sizeof(uint32_t)); *lenp = 0; client_get_msgs(sock, key, 0, lenp, &msgList); NUTS_TRUE(*lenp == 1 && msgList != NULL); @@ -166,13 +166,13 @@ test_exchange_client(void) NUTS_TRUE(rv == -1 && msgList == NULL); /* fuzz search start */ - lenp = nng_alloc(sizeof(int)); + lenp = nng_alloc(sizeof(uint32_t)); rv = exchange_client_get_msgs_fuzz(nni_sock_proto_data(nsock), 0, 3, lenp, &msgList); NUTS_TRUE(rv == 0 && *lenp == 1 && msgList != NULL); free_msg_list(msgList, NULL, lenp, 0); msgList = NULL; - int len = 0; + uint32_t len = 0; rv = exchange_client_get_msgs_fuzz(nni_sock_proto_data(nsock), 2, 3, &len, &msgList); NUTS_TRUE(rv != 0 && len == 0 && msgList == NULL); /* fuzz search end */ @@ -183,7 +183,7 @@ test_exchange_client(void) } /* Use aio recv to get msgs by key */ - lenp = nng_alloc(sizeof(int)); + lenp = nng_alloc(sizeof(uint32_t)); *lenp = 0; client_get_msgs(sock, 1, 10, lenp, &msgList); NUTS_TRUE(*lenp == 9 && msgList != NULL); diff --git a/src/sp/transport/mqtt/broker_tcp.c b/src/sp/transport/mqtt/broker_tcp.c index 8211a6c12..1b6b95646 100644 --- a/src/sp/transport/mqtt/broker_tcp.c +++ b/src/sp/transport/mqtt/broker_tcp.c @@ -73,7 +73,7 @@ struct tcptran_ep { bool closed; nng_url *url; nng_sockaddr src; - const conf *conf; + conf *conf; int refcnt; // active pipes nni_aio *useraio; nni_aio *connaio; diff --git a/src/sp/transport/mqtts/broker_tls.c b/src/sp/transport/mqtts/broker_tls.c index f44ee588b..7bcdae782 100644 --- a/src/sp/transport/mqtts/broker_tls.c +++ b/src/sp/transport/mqtts/broker_tls.c @@ -75,7 +75,7 @@ struct tlstran_ep { bool closed; nng_url *url; nng_sockaddr src; - const conf *conf; + conf *conf; nng_sockaddr sa; int refcnt; // active pipes int authmode; diff --git a/src/supplemental/nanolib/cmd.c b/src/supplemental/nanolib/cmd.c index 7f08480d9..4e6c4f009 100644 --- a/src/supplemental/nanolib/cmd.c +++ b/src/supplemental/nanolib/cmd.c @@ -90,8 +90,9 @@ nano_cmd_run(const char *cmd) if (error != 0) { log_warn("command '%s' returned an error", cmd); - if (cmd_output_len > 0) + if (cmd_output_len > 0) { log_debug(" %s", cmd_output_buff); + } ret = -1; } diff --git a/src/supplemental/nanolib/conf.c b/src/supplemental/nanolib/conf.c index bdb750639..dd6bb7088 100644 --- a/src/supplemental/nanolib/conf.c +++ b/src/supplemental/nanolib/conf.c @@ -50,9 +50,11 @@ static void conf_sqlite_destroy(conf_sqlite *sqlite); static void conf_web_hook_parse(conf_web_hook *webhook, const char *path); static void conf_web_hook_destroy(conf_web_hook *web_hook); +#if defined(ENABLE_LOG) static void conf_log_init(conf_log *log); static void conf_log_destroy(conf_log *log); static void conf_log_parse(conf_log *log, const char *path); +#endif #if defined(SUPP_RULE_ENGINE) static void conf_rule_repub_parse(conf_rule *cr, char *path); diff --git a/src/supplemental/nanolib/conf_ver2.c b/src/supplemental/nanolib/conf_ver2.c index 6f5ead9aa..a2f5e5fe1 100644 --- a/src/supplemental/nanolib/conf_ver2.c +++ b/src/supplemental/nanolib/conf_ver2.c @@ -1463,6 +1463,9 @@ conf_acl_parse_ver2(conf *config, cJSON *jso) } } } +#else + NNI_ARG_UNUSED(config); + NNI_ARG_UNUSED(jso); #endif } diff --git a/src/supplemental/nanolib/mqtt_db.c b/src/supplemental/nanolib/mqtt_db.c index ba16b2220..3c4a4af9e 100644 --- a/src/supplemental/nanolib/mqtt_db.c +++ b/src/supplemental/nanolib/mqtt_db.c @@ -1088,7 +1088,7 @@ collect_retain_well(void **vec, dbtree_node *node) nodes_t = NULL; } - return vec; + return (struct nng_msg **)vec; } /** @@ -1118,7 +1118,7 @@ collect_retains(void **vec, dbtree_node **nodes, dbtree_node **child = node_t->child; if (is_well(*topic_queue)) { - vec = collect_retain_well(vec, node_t); + vec = (void **)collect_retain_well(vec, node_t); break; } else if (is_plus(*topic_queue)) { if (*(topic_queue + 1) == NULL) { @@ -1177,7 +1177,7 @@ collect_retains(void **vec, dbtree_node **nodes, } } - return vec; + return (struct nng_msg **)vec; } nng_msg ** @@ -1203,12 +1203,12 @@ dbtree_find_retain(dbtree *db, char *topic) while (*topic_queue && (!cvector_empty(nodes))) { - rets = collect_retains(rets, nodes, &nodes_t, topic_queue); + rets = collect_retains((void **)rets, nodes, &nodes_t, topic_queue); topic_queue++; if (*topic_queue == NULL) { break; } - rets = collect_retains(rets, nodes_t, &nodes, topic_queue); + rets = collect_retains((void **)rets, nodes_t, &nodes, topic_queue); topic_queue++; } diff --git a/src/supplemental/nanolib/ringbuffer/ringbuffer.c b/src/supplemental/nanolib/ringbuffer/ringbuffer.c index 0903d3f25..ab72cebc4 100644 --- a/src/supplemental/nanolib/ringbuffer/ringbuffer.c +++ b/src/supplemental/nanolib/ringbuffer/ringbuffer.c @@ -225,7 +225,7 @@ static int write_msgs_to_file(ringBuffer_t *rb) nng_free(file, sizeof(ringBufferFile_t)); return -1; } - for (int i = 0; i < rb->cap; i++) { + for (unsigned int i = 0; i < rb->cap; i++) { file->keys[i] = rb->msgs[i].key; } @@ -239,7 +239,7 @@ static int write_msgs_to_file(ringBuffer_t *rb) } /* TODO: Path will return by parquet */ - sprintf(file->path, "/tmp/nanomq/RB%d", nng_timestamp()); + sprintf(file->path, "/tmp/nanomq/RB%ld", nng_timestamp()); cvector_push_back(rb->files, file); @@ -418,7 +418,7 @@ int ringBuffer_release(ringBuffer_t *rb) } if (rb->files != NULL) { - for (int i = 0; i < cvector_size(rb->files); i++) { + for (int i = 0; i < (int)cvector_size(rb->files); i++) { nng_free(rb->files[i]->keys, sizeof(uint64_t) * rb->cap); nng_free(rb->files[i]->path, sizeof(char) * 256); nng_free(rb->files[i], sizeof(ringBufferFile_t)); diff --git a/src/supplemental/nanolib/ringbuffer/ringbuffer_test.c b/src/supplemental/nanolib/ringbuffer/ringbuffer_test.c index 37cab323e..7ae3aeb55 100644 --- a/src/supplemental/nanolib/ringbuffer/ringbuffer_test.c +++ b/src/supplemental/nanolib/ringbuffer/ringbuffer_test.c @@ -36,9 +36,9 @@ void test_ringBuffer_release(void) return; } -static inline void free_msg_list(nng_msg **msgList, nng_msg *msg, int *lenp, int freeMsg) +static inline void free_msg_list(nng_msg **msgList, nng_msg *msg, uint32_t *lenp, int freeMsg) { - for (int i = 0; i < *lenp; i++) { + for (uint32_t i = 0; i < *lenp; i++) { if (freeMsg) { nng_msg_free(msgList[i]); } @@ -51,7 +51,7 @@ static inline void free_msg_list(nng_msg **msgList, nng_msg *msg, int *lenp, int nng_free(msgList, sizeof(nng_msg *) * (*lenp)); } if (lenp != NULL) { - nng_free(lenp, sizeof(int)); + nng_free(lenp, sizeof(uint32_t)); } } @@ -137,7 +137,7 @@ void test_ringBuffer_enqueue(void) nng_msg *msg = nng_aio_get_msg(aio); NUTS_TRUE(msg != NULL); - int *listLen = nng_msg_get_proto_data(msg); + uint32_t *listLen = nng_msg_get_proto_data(msg); NUTS_TRUE(listLen != NULL); NUTS_TRUE(*listLen == 10); @@ -423,15 +423,15 @@ void test_ringBuffer_search_msgs_by_key() NUTS_TRUE(ringBuffer_search_msgs_by_key(rb, 0, -1, &msgList) == -1); NUTS_TRUE(ringBuffer_search_msgs_by_key(rb, 0, 10, NULL) == -1); - int *lenp = NULL; - lenp = nng_alloc(sizeof(int)); + uint32_t *lenp = NULL; + lenp = nng_alloc(sizeof(uint32_t)); NUTS_TRUE(ringBuffer_search_msgs_by_key(rb, 0, 10, &msgList) == 0); *lenp = 10; free_msg_list(msgList, NULL, lenp, 0); NUTS_TRUE(ringBuffer_search_msgs_by_key(rb, 5, 10, &msgList) == 0); - lenp = nng_alloc(sizeof(int)); + lenp = nng_alloc(sizeof(uint32_t)); *lenp = 10; free_msg_list(msgList, NULL, lenp, 0); @@ -465,12 +465,12 @@ void test_ringBuffer_search_msgs_fuzz() ret = ringBuffer_search_msgs_fuzz(rb, start, end, lenp, &msgList); if (start / 10 == end / 10 && start % 10 != 0 && end % 10 != 0) { NUTS_TRUE(ret == -1); - nng_free(lenp, sizeof(int)); + nng_free(lenp, sizeof(uint32_t)); continue; } else { NUTS_TRUE(ret == 0); } - NUTS_TRUE(*lenp == ((end / 10 - (start % 10 == 0 ? start / 10 : start / 10 + 1)) + 1)); + NUTS_TRUE(*lenp == (uint32_t)((end / 10 - (start % 10 == 0 ? start / 10 : start / 10 + 1)) + 1)); free_msg_list(msgList, NULL, lenp, 0); } diff --git a/src/supplemental/util/platform.c b/src/supplemental/util/platform.c index 5eb25fda0..b4fa5e629 100644 --- a/src/supplemental/util/platform.c +++ b/src/supplemental/util/platform.c @@ -179,7 +179,7 @@ nng_random(void) } int -nng_socket_pair(int *fds) +nng_socket_pair(int fds[2]) { return (nni_socket_pair(fds)); }