Skip to content

Commit

Permalink
Fix more minor compiler warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Jan 21, 2021
1 parent cda8495 commit 706a1f3
Show file tree
Hide file tree
Showing 26 changed files with 250 additions and 22 deletions.
39 changes: 39 additions & 0 deletions apps/db_dump/stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,113 @@

struct mosquitto *context__init(mosq_sock_t sock)
{
UNUSED(sock);

return NULL;
}

int db__message_store(const struct mosquitto *source, struct mosquitto_msg_store *stored, uint32_t message_expiry_interval, dbid_t store_id, enum mosquitto_msg_origin origin)
{
UNUSED(source);
UNUSED(stored);
UNUSED(message_expiry_interval);
UNUSED(store_id);
UNUSED(origin);
return 0;
}

void db__msg_store_ref_inc(struct mosquitto_msg_store *store)
{
UNUSED(store);
}

int handle__packet(struct mosquitto *context)
{
UNUSED(context);
return 0;
}

int log__printf(struct mosquitto *mosq, unsigned int level, const char *fmt, ...)
{
UNUSED(mosq);
UNUSED(level);
UNUSED(fmt);
return 0;
}

FILE *mosquitto__fopen(const char *path, const char *mode, bool restrict_read)
{
UNUSED(path);
UNUSED(mode);
UNUSED(restrict_read);
return NULL;
}

enum mosquitto_client_state mosquitto__get_state(struct mosquitto *mosq)
{
UNUSED(mosq);
return mosq_cs_new;
}

int mux__add_out(struct mosquitto *mosq)
{
UNUSED(mosq);
return 0;
}

int mux__remove_out(struct mosquitto *mosq)
{
UNUSED(mosq);
return 0;
}

ssize_t net__read(struct mosquitto *mosq, void *buf, size_t count)
{
UNUSED(mosq);
UNUSED(buf);
UNUSED(count);
return 0;
}

ssize_t net__write(struct mosquitto *mosq, const void *buf, size_t count)
{
UNUSED(mosq);
UNUSED(buf);
UNUSED(count);
return 0;
}

int retain__store(const char *topic, struct mosquitto_msg_store *stored, char **split_topics)
{
UNUSED(topic);
UNUSED(stored);
UNUSED(split_topics);
return 0;
}

int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t identifier, int options, struct mosquitto__subhier **root)
{
UNUSED(context);
UNUSED(sub);
UNUSED(qos);
UNUSED(identifier);
UNUSED(options);
UNUSED(root);
return 0;
}

int sub__messages_queue(const char *source_id, const char *topic, uint8_t qos, int retain, struct mosquitto_msg_store **stored)
{
UNUSED(source_id);
UNUSED(topic);
UNUSED(qos);
UNUSED(retain);
UNUSED(stored);
return 0;
}

int keepalive__update(struct mosquitto *context)
{
UNUSED(context);
return 0;
}
1 change: 1 addition & 0 deletions apps/mosquitto_ctrl/dynsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ static void dynsec__payload_callback(struct mosq_ctrl *ctrl, long payloadlen, co
UNUSED(ctrl);

#if CJSON_VERSION_FULL < 1007013
UNUSED(payloadlen);
tree = cJSON_Parse(payload);
#else
tree = cJSON_ParseWithLength(payload, payloadlen);
Expand Down
5 changes: 5 additions & 0 deletions apps/mosquitto_ctrl/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
Contributors:
Roger Light - initial implementation and documentation.
*/
#include "config.h"

#include <cjson/cJSON.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -31,6 +33,9 @@ void ctrl_help(void)

int ctrl_main(int argc, char *argv[], struct mosq_ctrl *ctrl)
{
UNUSED(argc);
UNUSED(ctrl);

if(!strcasecmp(argv[0], "help")){
ctrl_help();
return -1;
Expand Down
2 changes: 1 addition & 1 deletion apps/mosquitto_passwd/mosquitto_passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ void handle_sigint(int signal)

static bool is_username_valid(const char *username)
{
int i;
size_t i;
size_t slen;

if(username){
Expand Down
4 changes: 2 additions & 2 deletions client/client_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int

static int check_format(const char *str)
{
int i;
size_t i;
size_t len;

len = strlen(str);
Expand Down Expand Up @@ -1395,7 +1395,7 @@ int client_connect(struct mosquitto *mosq, struct mosq_config *cfg)
/* Convert %25 -> %, %3a, %3A -> :, %40 -> @ */
static int mosquitto__urldecode(char *str)
{
int i, j;
size_t i, j;
size_t len;
if(!str) return 0;

Expand Down
2 changes: 1 addition & 1 deletion client/pub_shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int load_file(const char *filename)
return 1;
}
pos = 0;
while(pos < cfg.msglen){
while(pos < (size_t)cfg.msglen){
rlen = fread(&(cfg.message[pos]), sizeof(char), (size_t )cfg.msglen-pos, fptr);
pos += rlen;
}
Expand Down
7 changes: 6 additions & 1 deletion client/sub_client_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ static void write_payload(const unsigned char *payload, int payloadlen, int hex,
int i;
int padlen;

UNUSED(precision); /* FIXME - use or remove */

if(field_width > 0){
if(payloadlen > field_width){
payloadlen = field_width;
Expand Down Expand Up @@ -357,6 +359,9 @@ static int json_print(const struct mosquitto_message *message, const mosquitto_p

return MOSQ_ERR_SUCCESS;
#else
UNUSED(properties);
UNUSED(pretty);

strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S.000000Z%z", ti);
snprintf(&buf[strlen("2020-05-06T21:48:00.")], 9, "%06d", ns/1000);
buf[strlen("2020-05-06T21:48:00.000000")] = 'Z';
Expand Down Expand Up @@ -625,7 +630,7 @@ static void formatted_print_percent(const struct mosq_config *lcfg, const struct
static void formatted_print(const struct mosq_config *lcfg, const struct mosquitto_message *message, const mosquitto_property *properties)
{
size_t len;
int i;
size_t i;
struct tm *ti = NULL;
long ns = 0;
char strf[3] = {0, 0 ,0};
Expand Down
2 changes: 1 addition & 1 deletion lib/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int mosquitto_publish_v5(struct mosquitto *mosq, int *mid, const char *topic, in
}else{
tlen = strlen(topic);
if(mosquitto_validate_utf8(topic, (int)tlen)) return MOSQ_ERR_MALFORMED_UTF8;
if(payloadlen < 0 || payloadlen > MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE;
if(payloadlen < 0 || payloadlen > (int)MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE;
if(mosquitto_pub_topic_check(topic) != MOSQ_ERR_SUCCESS){
return MOSQ_ERR_INVAL;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/send_publish.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, uint8_t qos, bool retain, bool dup, const mosquitto_property *cmsg_props, const mosquitto_property *store_props, uint32_t expiry_interval)
{
#ifdef WITH_BROKER
size_t len;
#ifdef WITH_BRIDGE
size_t len;
int i;
struct mosquitto__bridge_topic *cur_topic;
bool match;
Expand Down
2 changes: 1 addition & 1 deletion lib/will_mosq.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int will__set(struct mosquitto *mosq, const char *topic, int payloadlen, const v
mosquitto_property *p;

if(!mosq || !topic) return MOSQ_ERR_INVAL;
if(payloadlen < 0 || payloadlen > MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE;
if(payloadlen < 0 || payloadlen > (int)MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE;
if(payloadlen > 0 && !payload) return MOSQ_ERR_INVAL;

if(mosquitto_pub_topic_check(topic)) return MOSQ_ERR_INVAL;
Expand Down
13 changes: 12 additions & 1 deletion plugins/message-timestamp/mosquitto_message_timestamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*
* Note that this only works on Mosquitto 2.0 or later.
*/

#include "config.h"

#include <stdio.h>
#include <time.h>
Expand All @@ -47,6 +47,9 @@ static int callback_message(int event, void *event_data, void *userdata)
struct tm *ti;
char time_buf[25];

UNUSED(event);
UNUSED(userdata);

clock_gettime(CLOCK_REALTIME, &ts);
ti = gmtime(&ts.tv_sec);
strftime(time_buf, sizeof(time_buf), "%Y-%m-%dT%H:%M:%SZ", ti);
Expand All @@ -68,11 +71,19 @@ int mosquitto_plugin_version(int supported_version_count, const int *supported_v

int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **user_data, struct mosquitto_opt *opts, int opt_count)
{
UNUSED(user_data);
UNUSED(opts);
UNUSED(opt_count);

mosq_pid = identifier;
return mosquitto_callback_register(mosq_pid, MOSQ_EVT_MESSAGE, callback_message, NULL, NULL);
}

int mosquitto_plugin_cleanup(void *user_data, struct mosquitto_opt *opts, int opt_count)
{
UNUSED(user_data);
UNUSED(opts);
UNUSED(opt_count);

return mosquitto_callback_unregister(mosq_pid, MOSQ_EVT_MESSAGE, callback_message, NULL);
}
2 changes: 1 addition & 1 deletion src/handle_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ static int will__read(struct mosquitto *context, const char *client_id, struct m

will_struct->msg.payloadlen = payloadlen;
if(will_struct->msg.payloadlen > 0){
if(db.config->message_size_limit && will_struct->msg.payloadlen > db.config->message_size_limit){
if(db.config->message_size_limit && will_struct->msg.payloadlen > (int)db.config->message_size_limit){
log__printf(NULL, MOSQ_LOG_DEBUG, "Client %s connected with too large Will payload", client_id);
if(context->protocol == mosq_p_mqtt5){
send__connack(context, 0, MQTT_RC_PACKET_TOO_LARGE, NULL);
Expand Down
14 changes: 7 additions & 7 deletions src/mux_poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int mux_poll__init(struct mosquitto__listener_sock *listensock, int listensock_c
pollfds[i].fd = INVALID_SOCKET;
}

for(i=0; i<listensock_count; i++){
for(i=0; i<(size_t )listensock_count; i++){
pollfds[pollfd_index].fd = listensock[i].sock;
pollfds[pollfd_index].events = POLLIN;
pollfds[pollfd_index].revents = 0;
Expand All @@ -108,7 +108,7 @@ int mux_poll__init(struct mosquitto__listener_sock *listensock, int listensock_c

int mux_poll__add_out(struct mosquitto *context)
{
int i;
size_t i;

if(!(context->events & POLLOUT)) {
if(context->pollfd_index != -1){
Expand All @@ -121,9 +121,9 @@ int mux_poll__add_out(struct mosquitto *context)
pollfds[i].fd = context->sock;
pollfds[i].events = POLLIN | POLLOUT;
pollfds[i].revents = 0;
context->pollfd_index = i;
context->pollfd_index = (int )i;
if(i > pollfd_current_max){
pollfd_current_max = (size_t )i;
pollfd_current_max = i;
}
break;
}
Expand All @@ -148,7 +148,7 @@ int mux_poll__remove_out(struct mosquitto *context)

int mux_poll__add_in(struct mosquitto *context)
{
int i;
size_t i;

if(context->pollfd_index != -1){
pollfds[context->pollfd_index].fd = context->sock;
Expand All @@ -160,9 +160,9 @@ int mux_poll__add_in(struct mosquitto *context)
pollfds[i].fd = context->sock;
pollfds[i].events = POLLIN;
pollfds[i].revents = 0;
context->pollfd_index = i;
context->pollfd_index = (int )i;
if(i > pollfd_current_max){
pollfd_current_max = (size_t )i;
pollfd_current_max = i;
}
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,13 @@ int net__tls_load_verify(struct mosquitto__listener *listener)


#ifndef WIN32
static int net__bind_interface(struct mosquitto__listener *listener, mosq_sock_t sock, struct addrinfo *rp)
static int net__bind_interface(struct mosquitto__listener *listener, struct addrinfo *rp)
{
/*
* This binds the listener sock to a network interface.
* The use of SO_BINDTODEVICE requires root access, which we don't have, so instead
* use getifaddrs to find the interface addresses, and attempt to bind to
* the IP of the matching interface.
* use getifaddrs to find the interface addresses, and use IP of the
* matching interface in the later bind().
*/
struct ifaddrs *ifaddr, *ifa;
if(getifaddrs(&ifaddr) < 0){
Expand Down Expand Up @@ -725,7 +725,7 @@ static int net__socket_listen_tcp(struct mosquitto__listener *listener)

#ifndef WIN32
if(listener->bind_interface){
if(net__bind_interface(listener, sock, rp)){
if(net__bind_interface(listener, rp)){
COMPAT_CLOSE(sock);
freeaddrinfo(ainfo);
mosquitto__free(listener->socks);
Expand Down
2 changes: 2 additions & 0 deletions src/plugin_public.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ int mosquitto_client_protocol(const struct mosquitto *client)
if(client && client->wsi){
return mp_websockets;
}else
#else
UNUSED(client);
#endif
{
return mp_mqtt;
Expand Down
2 changes: 1 addition & 1 deletion src/security_default.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ static int mosquitto_acl_check_default(int event, void *event_data, void *userda
char *local_acl;
struct mosquitto__acl *acl_root;
bool result;
int i;
size_t i;
size_t len, tlen, clen, ulen;
char *s;
struct mosquitto__security_options *security_opts = NULL;
Expand Down
3 changes: 3 additions & 0 deletions test/unit/bridge_topic_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ int main(int argc, char *argv[])
{
unsigned int fails;

UNUSED(argc);
UNUSED(argv);

if(CU_initialize_registry() != CUE_SUCCESS){
printf("Error initializing CUnit registry.\n");
return 1;
Expand Down
Loading

0 comments on commit 706a1f3

Please sign in to comment.