Skip to content

Commit

Permalink
use const for buf_end
Browse files Browse the repository at this point in the history
  • Loading branch information
256dpi committed Sep 29, 2017
1 parent 40d9f54 commit de29279
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "helpers.h"

lwmqtt_err_t lwmqtt_read_data(uint8_t **buf, uint8_t *buf_end, uint8_t **data, size_t len) {
lwmqtt_err_t lwmqtt_read_data(uint8_t **buf, const uint8_t *buf_end, uint8_t **data, size_t len) {
// check zero length
if (len == 0) {
*data = NULL;
Expand All @@ -23,7 +23,7 @@ lwmqtt_err_t lwmqtt_read_data(uint8_t **buf, uint8_t *buf_end, uint8_t **data, s
return LWMQTT_SUCCESS;
}

lwmqtt_err_t lwmqtt_write_data(uint8_t **buf, uint8_t *buf_end, uint8_t *data, size_t len) {
lwmqtt_err_t lwmqtt_write_data(uint8_t **buf, const uint8_t *buf_end, uint8_t *data, size_t len) {
// check zero length
if (len == 0) {
return LWMQTT_SUCCESS;
Expand All @@ -43,7 +43,7 @@ lwmqtt_err_t lwmqtt_write_data(uint8_t **buf, uint8_t *buf_end, uint8_t *data, s
return LWMQTT_SUCCESS;
}

lwmqtt_err_t lwmqtt_read_num(uint8_t **buf, uint8_t *buf_end, uint16_t *num) {
lwmqtt_err_t lwmqtt_read_num(uint8_t **buf, const uint8_t *buf_end, uint16_t *num) {
// check buffer size
if ((size_t)(buf_end - (*buf)) < 2) {
*num = 0;
Expand All @@ -59,7 +59,7 @@ lwmqtt_err_t lwmqtt_read_num(uint8_t **buf, uint8_t *buf_end, uint16_t *num) {
return LWMQTT_SUCCESS;
}

lwmqtt_err_t lwmqtt_write_num(uint8_t **buf, uint8_t *buf_end, uint16_t num) {
lwmqtt_err_t lwmqtt_write_num(uint8_t **buf, const uint8_t *buf_end, uint16_t num) {
// check buffer size
if ((size_t)(buf_end - (*buf)) < 2) {
return LWMQTT_BUFFER_TOO_SHORT;
Expand All @@ -75,7 +75,7 @@ lwmqtt_err_t lwmqtt_write_num(uint8_t **buf, uint8_t *buf_end, uint16_t num) {
return LWMQTT_SUCCESS;
}

lwmqtt_err_t lwmqtt_read_string(uint8_t **buf, uint8_t *buf_end, lwmqtt_string_t *str) {
lwmqtt_err_t lwmqtt_read_string(uint8_t **buf, const uint8_t *buf_end, lwmqtt_string_t *str) {
// read length
uint16_t len;
lwmqtt_err_t err = lwmqtt_read_num(buf, buf_end, &len);
Expand All @@ -95,7 +95,7 @@ lwmqtt_err_t lwmqtt_read_string(uint8_t **buf, uint8_t *buf_end, lwmqtt_string_t
return LWMQTT_SUCCESS;
}

lwmqtt_err_t lwmqtt_write_string(uint8_t **buf, uint8_t *buf_end, lwmqtt_string_t str) {
lwmqtt_err_t lwmqtt_write_string(uint8_t **buf, const uint8_t *buf_end, lwmqtt_string_t str) {
// write string length
lwmqtt_err_t err = lwmqtt_write_num(buf, buf_end, str.len);
if (err != LWMQTT_SUCCESS) {
Expand All @@ -111,7 +111,7 @@ lwmqtt_err_t lwmqtt_write_string(uint8_t **buf, uint8_t *buf_end, lwmqtt_string_
return LWMQTT_SUCCESS;
}

lwmqtt_err_t lwmqtt_read_byte(uint8_t **buf, uint8_t *buf_end, uint8_t *byte) {
lwmqtt_err_t lwmqtt_read_byte(uint8_t **buf, const uint8_t *buf_end, uint8_t *byte) {
// check buffer size
if ((size_t)(buf_end - (*buf)) < 1) {
*byte = 0;
Expand All @@ -127,7 +127,7 @@ lwmqtt_err_t lwmqtt_read_byte(uint8_t **buf, uint8_t *buf_end, uint8_t *byte) {
return LWMQTT_SUCCESS;
}

lwmqtt_err_t lwmqtt_write_byte(uint8_t **buf, uint8_t *buf_end, uint8_t byte) {
lwmqtt_err_t lwmqtt_write_byte(uint8_t **buf, const uint8_t *buf_end, uint8_t byte) {
// check buffer size
if ((size_t)(buf_end - (*buf)) < 1) {
return LWMQTT_BUFFER_TOO_SHORT;
Expand Down Expand Up @@ -161,7 +161,7 @@ lwmqtt_err_t lwmqtt_varnum_length(uint32_t varnum, int *len) {
}
}

lwmqtt_err_t lwmqtt_read_varnum(uint8_t **buf, uint8_t *buf_end, uint32_t *varnum) {
lwmqtt_err_t lwmqtt_read_varnum(uint8_t **buf, const uint8_t *buf_end, uint32_t *varnum) {
// prepare last byte
uint8_t byte;

Expand Down Expand Up @@ -205,7 +205,7 @@ lwmqtt_err_t lwmqtt_read_varnum(uint8_t **buf, uint8_t *buf_end, uint32_t *varnu
return LWMQTT_SUCCESS;
}

lwmqtt_err_t lwmqtt_write_varnum(uint8_t **buf, uint8_t *buf_end, uint32_t varnum) {
lwmqtt_err_t lwmqtt_write_varnum(uint8_t **buf, const uint8_t *buf_end, uint32_t varnum) {
// init len counter
size_t len = 0;

Expand Down
20 changes: 10 additions & 10 deletions src/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @param len - The amount of data to read.
* @return LWMQTT_SUCCESS or LWMQTT_BUFFER_TOO_SHORT.
*/
lwmqtt_err_t lwmqtt_read_data(uint8_t **buf, uint8_t *buf_end, uint8_t **data, size_t len);
lwmqtt_err_t lwmqtt_read_data(uint8_t **buf, const uint8_t *buf_end, uint8_t **data, size_t len);

/**
* Writes arbitrary data to the specified buffer. The pointer is incremented by the bytes written.
Expand All @@ -23,7 +23,7 @@ lwmqtt_err_t lwmqtt_read_data(uint8_t **buf, uint8_t *buf_end, uint8_t **data, s
* @param len - The amount of data to write.
* @return LWMQTT_SUCCESS or LWMQTT_BUFFER_TOO_SHORT.
*/
lwmqtt_err_t lwmqtt_write_data(uint8_t **buf, uint8_t *buf_end, uint8_t *data, size_t len);
lwmqtt_err_t lwmqtt_write_data(uint8_t **buf, const uint8_t *buf_end, uint8_t *data, size_t len);

/**
* Reads two byte number from the specified buffer. The pointer is incremented by two.
Expand All @@ -33,7 +33,7 @@ lwmqtt_err_t lwmqtt_write_data(uint8_t **buf, uint8_t *buf_end, uint8_t *data, s
* @param num - The read number.
* @return LWMQTT_SUCCESS or LWMQTT_BUFFER_TOO_SHORT.
*/
lwmqtt_err_t lwmqtt_read_num(uint8_t **buf, uint8_t *buf_end, uint16_t *num);
lwmqtt_err_t lwmqtt_read_num(uint8_t **buf, const uint8_t *buf_end, uint16_t *num);

/**
* Writes a two byte number to the specified buffer. The pointer is incremented by two.
Expand All @@ -43,7 +43,7 @@ lwmqtt_err_t lwmqtt_read_num(uint8_t **buf, uint8_t *buf_end, uint16_t *num);
* @param num - The number to write.
* @return LWMQTT_SUCCESS or LWMQTT_BUFFER_TOO_SHORT.
*/
lwmqtt_err_t lwmqtt_write_num(uint8_t **buf, uint8_t *buf_end, uint16_t num);
lwmqtt_err_t lwmqtt_write_num(uint8_t **buf, const uint8_t *buf_end, uint16_t num);

/**
* Reads a string from the specified buffer into the passed object. The pointer is incremented by the bytes read.
Expand All @@ -53,7 +53,7 @@ lwmqtt_err_t lwmqtt_write_num(uint8_t **buf, uint8_t *buf_end, uint16_t num);
* @param str - The object into which the data is to be read.
* @return LWMQTT_SUCCESS or LWMQTT_BUFFER_TOO_SHORT.
*/
lwmqtt_err_t lwmqtt_read_string(uint8_t **buf, uint8_t *buf_end, lwmqtt_string_t *str);
lwmqtt_err_t lwmqtt_read_string(uint8_t **buf, const uint8_t *buf_end, lwmqtt_string_t *str);

/**
* Writes a string to the specified buffer. The pointer is incremented by the bytes written.
Expand All @@ -63,7 +63,7 @@ lwmqtt_err_t lwmqtt_read_string(uint8_t **buf, uint8_t *buf_end, lwmqtt_string_t
* @param str - The string to write.
* @return LWMQTT_SUCCESS or LWMQTT_BUFFER_TOO_SHORT.
*/
lwmqtt_err_t lwmqtt_write_string(uint8_t **buf, uint8_t *buf_end, lwmqtt_string_t str);
lwmqtt_err_t lwmqtt_write_string(uint8_t **buf, const uint8_t *buf_end, lwmqtt_string_t str);

/**
* Reads one byte from the buffer. The pointer is incremented by one.
Expand All @@ -73,7 +73,7 @@ lwmqtt_err_t lwmqtt_write_string(uint8_t **buf, uint8_t *buf_end, lwmqtt_string_
* @param byte - The read byte.
* @return LWMQTT_SUCCESS or LWMQTT_BUFFER_TOO_SHORT.
*/
lwmqtt_err_t lwmqtt_read_byte(uint8_t **buf, uint8_t *buf_end, uint8_t *byte);
lwmqtt_err_t lwmqtt_read_byte(uint8_t **buf, const uint8_t *buf_end, uint8_t *byte);

/**
* Writes one byte to the specified buffer. The pointer is incremented by one.
Expand All @@ -83,7 +83,7 @@ lwmqtt_err_t lwmqtt_read_byte(uint8_t **buf, uint8_t *buf_end, uint8_t *byte);
* @param byte - The byte to write.
* @return LWMQTT_SUCCESS or LWMQTT_BUFFER_TOO_SHORT.
*/
lwmqtt_err_t lwmqtt_write_byte(uint8_t **buf, uint8_t *buf_end, uint8_t byte);
lwmqtt_err_t lwmqtt_write_byte(uint8_t **buf, const uint8_t *buf_end, uint8_t byte);

/**
* Returns the amount of bytes required by the variable number.
Expand All @@ -102,7 +102,7 @@ lwmqtt_err_t lwmqtt_varnum_length(uint32_t varnum, int *len);
* @param varnum - The read varnum.
* @return LWMQTT_SUCCESS, LWMQTT_BUFFER_TOO_SHORT or LWMQTT_VARNUM_OVERFLOW.
*/
lwmqtt_err_t lwmqtt_read_varnum(uint8_t **buf, uint8_t *buf_end, uint32_t *varnum);
lwmqtt_err_t lwmqtt_read_varnum(uint8_t **buf, const uint8_t *buf_end, uint32_t *varnum);

/**
* Writes a variable number to the specified buffer. The pointer is incremented by the bytes written.
Expand All @@ -112,6 +112,6 @@ lwmqtt_err_t lwmqtt_read_varnum(uint8_t **buf, uint8_t *buf_end, uint32_t *varnu
* @param varnum - The number to write.
* @return LWMQTT_SUCCESS, LWMQTT_BUFFER_TOO_SHORT or LWMQTT_VARNUM_OVERFLOW.
*/
lwmqtt_err_t lwmqtt_write_varnum(uint8_t **buf, uint8_t *buf_end, uint32_t varnum);
lwmqtt_err_t lwmqtt_write_varnum(uint8_t **buf, const uint8_t *buf_end, uint32_t varnum);

#endif

0 comments on commit de29279

Please sign in to comment.