Skip to content

Commit

Permalink
shell: mqtt: fix uint32_t compared against 0
Browse files Browse the repository at this point in the history
Fix unsigned compared against 0 reported by coverity check.
CID: 321096

Signed-off-by: Yong Cong Sin <[email protected]>
  • Loading branch information
ycsin authored and fabiobaltieri committed Jul 11, 2023
1 parent 934c6d7 commit 7fba7d3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions subsys/shell/backends/shell_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,9 @@ static void mqtt_evt_handler(struct mqtt_client *const client, const struct mqtt

case MQTT_EVT_PUBLISH: {
const struct mqtt_publish_param *pub = &evt->param.publish;
uint32_t size, payload_left;
uint32_t payload_left;
size_t size;
int rc;

payload_left = pub->message.payload.len;

Expand All @@ -581,18 +583,19 @@ static void mqtt_evt_handler(struct mqtt_client *const client, const struct mqtt

while (payload_left > 0) {
/* Attempt to claim `payload_left` bytes of buffer in rb */
size = ring_buf_put_claim(&sh_mqtt->rx_rb, &sh_mqtt->rx_rb_ptr,
payload_left);
size = (size_t)ring_buf_put_claim(&sh_mqtt->rx_rb, &sh_mqtt->rx_rb_ptr,
payload_left);
/* Read `size` bytes of payload from mqtt */
size = mqtt_read_publish_payload_blocking(client, sh_mqtt->rx_rb_ptr, size);
rc = mqtt_read_publish_payload_blocking(client, sh_mqtt->rx_rb_ptr, size);

/* errno value, return */
if (size < 0) {
if (rc < 0) {
(void)ring_buf_put_finish(&sh_mqtt->rx_rb, 0U);
sh_mqtt_rx_rb_flush();
return;
}

size = (size_t)rc;
/* Indicate that `size` bytes of payload has been written into rb */
(void)ring_buf_put_finish(&sh_mqtt->rx_rb, size);
/* Update `payload_left` */
Expand Down

0 comments on commit 7fba7d3

Please sign in to comment.