Skip to content

Commit

Permalink
Fixes for scan-build and G++ compiler warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed Apr 27, 2020
1 parent d29bf75 commit 2094c31
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
8 changes: 4 additions & 4 deletions examples/multithread/multithread.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static void *subscribe_task(void *param)
{
int rc = MQTT_CODE_SUCCESS;
uint16_t i;
MQTTCtx *mqttCtx = param;
MQTTCtx *mqttCtx = (MQTTCtx*)param;

/* Build list of topics */
XMEMSET(&mqttCtx->subscribe, 0, sizeof(MqttSubscribe));
Expand Down Expand Up @@ -375,7 +375,7 @@ static void *waitMessage_task(void *param)
#endif
{
int rc;
MQTTCtx *mqttCtx = param;
MQTTCtx *mqttCtx = (MQTTCtx*)param;

/* Read Loop */
PRINTF("MQTT Waiting for message...");
Expand Down Expand Up @@ -453,7 +453,7 @@ static void *publish_task(void *param)
{
int rc;
char buf[7];
MQTTCtx *mqttCtx = param;
MQTTCtx *mqttCtx = (MQTTCtx*)param;
MqttPublish publish;

/* Publish Topic */
Expand Down Expand Up @@ -485,7 +485,7 @@ static void *ping_task(void *param)
#endif
{
int rc;
MQTTCtx *mqttCtx = param;
MQTTCtx *mqttCtx = (MQTTCtx*)param;
MqttPing ping;

XMEMSET(&ping, 0, sizeof(ping));
Expand Down
30 changes: 17 additions & 13 deletions src/mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ static int MqttClient_WaitType(MqttClient *client, void *packet_obj,
MqttPacket_TypeDesc(wait_type), wait_type, wait_packet_id);
#endif

switch (*mms_stat)
switch ((int)*mms_stat)
{
case MQTT_MSG_BEGIN:
{
Expand Down Expand Up @@ -776,8 +776,8 @@ static int MqttClient_WaitType(MqttClient *client, void *packet_obj,
pendResp = NULL;
rc = wm_SemLock(&client->lockClient);
if (rc == 0) {
if (MqttClient_RespList_Find(client, wait_type, wait_packet_id,
&pendResp)) {
if (MqttClient_RespList_Find(client, (MqttPacketType)wait_type,
wait_packet_id, &pendResp)) {
if (pendResp->packetDone) {
/* pending response is already done, so return */
rc = pendResp->packet_ret;
Expand Down Expand Up @@ -2336,19 +2336,23 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj,
{
int rc;
SN_MsgType packet_type;
word16 packet_id = 0;
MqttMsgStat* stat;
word16 packet_id;
MqttMsgStat* mms_stat;

if (client == NULL || packet_obj == NULL) {
return MQTT_CODE_ERROR_BAD_ARG;
}

/* all packet type structures must have MqttMsgStat at top */
stat = (MqttMsgStat*)packet_obj;
mms_stat = (MqttMsgStat*)packet_obj;

wait_again:

switch ((int)*stat)
/* initialize variables */
packet_id = 0;
packet_type = SN_MSG_TYPE_RESERVED;

switch ((int)*mms_stat)
{
case MQTT_MSG_BEGIN:
{
Expand All @@ -2366,7 +2370,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj,
return rc;
}

*stat = MQTT_MSG_WAIT;
*mms_stat = MQTT_MSG_WAIT;
client->packet.buf_len = rc;

/* Decode header */
Expand All @@ -2380,15 +2384,15 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj,
client->packet.buf_len, packet_type);
#endif

*stat = MQTT_MSG_READ;
*mms_stat = MQTT_MSG_READ;

FALL_THROUGH;
}

case MQTT_MSG_READ:
case MQTT_MSG_READ_PAYLOAD:
{
if (*stat == MQTT_MSG_READ_PAYLOAD) {
if (*mms_stat == MQTT_MSG_READ_PAYLOAD) {
packet_type = SN_MSG_TYPE_PUBLISH;
}
rc = SN_Client_HandlePacket(client, packet_type, packet_obj,
Expand All @@ -2405,7 +2409,7 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj,
break;
}

*stat = MQTT_MSG_BEGIN;
*mms_stat = MQTT_MSG_BEGIN;
goto wait_again;
}

Expand All @@ -2416,15 +2420,15 @@ static int SN_Client_WaitType(MqttClient *client, void* packet_obj,
default:
{
#ifdef WOLFMQTT_DEBUG_CLIENT
PRINTF("SN_Client_WaitType: Invalid state %d!", *stat);
PRINTF("SN_Client_WaitType: Invalid state %d!", *mms_stat);
#endif
rc = MQTT_CODE_ERROR_STAT;
break;
}
} /* switch (msg->stat) */

/* reset state */
*stat = MQTT_MSG_BEGIN;
*mms_stat = MQTT_MSG_BEGIN;

return rc;
}
Expand Down
10 changes: 5 additions & 5 deletions src/mqtt_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,8 @@ int MqttEncode_Publish(byte *tx_buf, int tx_buf_len, MqttPublish *publish,
tx_payload += MqttEncode_Vbi(tx_payload, props_len);

/* Encode properties */
tx_payload += MqttEncode_Props(publish->type, publish->props,
tx_payload);
tx_payload += MqttEncode_Props((MqttPacketType)publish->type,
publish->props, tx_payload);
}
#endif

Expand Down Expand Up @@ -912,8 +912,8 @@ int MqttDecode_Publish(byte *rx_buf, int rx_buf_len, MqttPublish *publish)
variable_len += tmp + props_len;
if (props_len > 0) {
/* Decode the Properties */
rx_payload += MqttDecode_Props(publish->type, &publish->props,
rx_payload, props_len);
rx_payload += MqttDecode_Props((MqttPacketType)publish->type,
&publish->props, rx_payload, props_len);
if (publish->props != NULL) {
/* Parse properties. */
}
Expand Down Expand Up @@ -1854,7 +1854,7 @@ int SN_Decode_Header(byte *rx_buf, int rx_buf_len,
}

/* Message Type */
packet_type = *rx_buf++;
packet_type = (SN_MsgType)*rx_buf++;

if (p_packet_type)
*p_packet_type = packet_type;
Expand Down
3 changes: 2 additions & 1 deletion wolfmqtt/mqtt_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,9 @@ typedef enum _SN_MsgType {
SN_MSG_TYPE_WILLMSGUPD = 0x1C,
SN_MSG_TYPE_WILLMSGRESP = 0x1D,
/* 0x1E - 0xFD reserved */
SN_MSG_TYPE_ENCAPMSG = 0xFE /* Encapsulated message */
SN_MSG_TYPE_ENCAPMSG = 0xFE, /* Encapsulated message */
/* 0xFF reserved */
SN_MSG_TYPE_RESERVED = 0xFF
} SN_MsgType;

/* Topic ID types */
Expand Down

0 comments on commit 2094c31

Please sign in to comment.