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

more linting #174

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
refactor types in mqtt_message_queue
avoid many cast
  • Loading branch information
fperrad committed Nov 23, 2022
commit 4a18fe9808076804a783e5e9fe008b36099b0668
8 changes: 4 additions & 4 deletions include/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -973,10 +973,10 @@ struct mqtt_message_queue {
*
* @warning This member should \em not be manually changed.
*/
void *mem_start;
uint8_t *mem_start;

/** @brief The end of the message queue's memory block. */
void *mem_end;
struct mqtt_queued_message *mem_end;

/**
* @brief A pointer to the position in the buffer you can pack bytes at.
Expand Down Expand Up @@ -1069,13 +1069,13 @@ struct mqtt_queued_message* mqtt_mq_find(const struct mqtt_message_queue *mq, en
*
* @returns The mqtt_queued_message at \p index.
*/
#define mqtt_mq_get(mq_ptr, index) (((struct mqtt_queued_message*) ((mq_ptr)->mem_end)) - 1 - index)
#define mqtt_mq_get(mq_ptr, index) ((mq_ptr)->mem_end - 1 - index)

/**
* @brief Returns the number of messages in the message queue, \p mq_ptr.
* @ingroup details
*/
#define mqtt_mq_length(mq_ptr) (((struct mqtt_queued_message*) ((mq_ptr)->mem_end)) - (mq_ptr)->queue_tail)
#define mqtt_mq_length(mq_ptr) ((mq_ptr)->mem_end - (mq_ptr)->queue_tail)

/**
* @brief Used internally to recalculate the \c curr_sz.
Expand Down
14 changes: 7 additions & 7 deletions src/mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1619,9 +1619,9 @@ ssize_t mqtt_pack_unsubscribe_request(uint8_t *buf, size_t bufsz, unsigned int p
void mqtt_mq_init(struct mqtt_message_queue *mq, void *buf, size_t bufsz)
{
mq->mem_start = buf;
mq->mem_end = (uint8_t *)buf + bufsz;
mq->curr = (uint8_t *)buf;
mq->queue_tail = (struct mqtt_queued_message *)mq->mem_end;
mq->mem_end = (struct mqtt_queued_message *)(mq->mem_start + bufsz);
mq->curr = mq->mem_start;
mq->queue_tail = mq->mem_end;
mq->curr_sz = (buf == NULL) ? 0 : mqtt_mq_currsz(mq);
}

Expand Down Expand Up @@ -1649,8 +1649,8 @@ void mqtt_mq_clean(struct mqtt_message_queue *mq) {

/* check if everything can be removed */
if (new_head < mq->queue_tail) {
mq->curr = (uint8_t *)mq->mem_start;
mq->queue_tail = (struct mqtt_queued_message *)mq->mem_end;
mq->curr = mq->mem_start;
mq->queue_tail = mq->mem_end;
mq->curr_sz = mqtt_mq_currsz(mq);
return;
}
Expand All @@ -1662,9 +1662,9 @@ void mqtt_mq_clean(struct mqtt_message_queue *mq) {
/* move buffered data */
{
size_t n = (size_t) (mq->curr - new_head->start);
size_t removing = (size_t) (new_head->start - (uint8_t*) mq->mem_start);
size_t removing = (size_t) (new_head->start - mq->mem_start);
memmove(mq->mem_start, new_head->start, n);
mq->curr = (unsigned char*)mq->mem_start + n;
mq->curr = mq->mem_start + n;


/* move queue */
Expand Down