From de292793932117bb854c1b7c118d87a5ef9437fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20G=C3=A4hwiler?= Date: Fri, 29 Sep 2017 15:42:04 +0200 Subject: [PATCH] use const for buf_end --- src/helpers.c | 20 ++++++++++---------- src/helpers.h | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/helpers.c b/src/helpers.c index 54695b8..28a6d73 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -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; @@ -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; @@ -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; @@ -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; @@ -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); @@ -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) { @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/src/helpers.h b/src/helpers.h index a87abc8..b3ab05d 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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