Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up some code warning #821

Merged
merged 13 commits into from
Jan 23, 2024
Merged
4 changes: 2 additions & 2 deletions include/nng/supplemental/nanolib/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
3 changes: 1 addition & 2 deletions include/nng/supplemental/nanolib/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ NNG_DECL void log_clear_callback();
#define log_warn(...)
#define log_error(...)
#define log_fatal(...)

#endif


#ifdef __cplusplus
}
#endif

#endif
#endif
2 changes: 1 addition & 1 deletion src/core/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a warning of nng.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, this shall not be modified

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nng already fixed this in nanomsg/nng#1760

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then there shall be sth wrong on sync....


//
// File/Store Support
Expand Down
2 changes: 1 addition & 1 deletion src/core/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
19 changes: 9 additions & 10 deletions src/mqtt/protocol/exchange/exchange_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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';
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions src/mqtt/protocol/exchange/exchange_server_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand All @@ -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));
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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 */
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/sp/transport/mqtt/broker_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/sp/transport/mqtts/broker_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/supplemental/nanolib/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/supplemental/nanolib/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/supplemental/nanolib/conf_ver2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,9 @@ conf_acl_parse_ver2(conf *config, cJSON *jso)
}
}
}
#else
NNI_ARG_UNUSED(config);
NNI_ARG_UNUSED(jso);
#endif
}

Expand Down
10 changes: 5 additions & 5 deletions src/supplemental/nanolib/mqtt_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ collect_retain_well(void **vec, dbtree_node *node)
nodes_t = NULL;
}

return vec;
return (struct nng_msg **)vec;
}

/**
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1177,7 +1177,7 @@ collect_retains(void **vec, dbtree_node **nodes,
}
}

return vec;
return (struct nng_msg **)vec;
}

nng_msg **
Expand All @@ -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++;
}

Expand Down
6 changes: 3 additions & 3 deletions src/supplemental/nanolib/ringbuffer/ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);

Expand Down Expand Up @@ -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));
Expand Down
18 changes: 9 additions & 9 deletions src/supplemental/nanolib/ringbuffer/ringbuffer_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}

Expand Down
Loading
Loading