From a9eaf979df4817f9a1c0c96a1b1150a8efc068ec Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Sun, 8 Sep 2019 15:13:27 +0200 Subject: [PATCH 1/4] remove useless initialization --- test/buf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/buf.c b/test/buf.c index e2d9725..44ba3e3 100644 --- a/test/buf.c +++ b/test/buf.c @@ -158,8 +158,8 @@ void M_BufferSetString(buf_t *buf, const char *data, size_t length) { } bool M_BufferSetFile(buf_t *buf, const char *filename) { - FILE *fp = NULL; - size_t length = 0; + FILE *fp; + size_t length; bool out = false; if ((fp = fopen(filename, "rb")) == NULL) From edd371716377033607c46a0a0e5fa90cc9128aae Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Mon, 7 Sep 2020 08:42:54 +0200 Subject: [PATCH 2/4] remove useless include --- test/profile.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/profile.c b/test/profile.c index 4170859..5a20f71 100644 --- a/test/profile.c +++ b/test/profile.c @@ -22,8 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include - #include "tests.h" int main(void) { From 209e4aca1bc42588fd69f8646183d259109d4c78 Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Mon, 7 Sep 2020 08:53:24 +0200 Subject: [PATCH 3/4] refactor includes in test/ --- test/profile.c | 2 ++ test/test.c | 1 + test/tests.h | 11 ----------- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/test/profile.c b/test/profile.c index 5a20f71..80bf9d0 100644 --- a/test/profile.c +++ b/test/profile.c @@ -22,6 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include + #include "tests.h" int main(void) { diff --git a/test/test.c b/test/test.c index b79a3eb..89d263e 100644 --- a/test/test.c +++ b/test/test.c @@ -25,6 +25,7 @@ THE SOFTWARE. #include #include #include +#include #include diff --git a/test/tests.h b/test/tests.h index 6d540b8..57f458c 100644 --- a/test/tests.h +++ b/test/tests.h @@ -22,17 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include - void test_msgpack(void **state); void test_fixedint(void **state); void test_numbers(void **state); From 24a8b2290b713dad73f8efc93696e99de94b7367 Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Sun, 8 Sep 2019 15:10:30 +0200 Subject: [PATCH 4/4] constify parameter --- test/buf.c | 30 +++++++++++++++--------------- test/buf.h | 30 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/test/buf.c b/test/buf.c index 44ba3e3..e2c247f 100644 --- a/test/buf.c +++ b/test/buf.c @@ -72,23 +72,23 @@ void M_BufferInitWithCapacity(buf_t *buf, size_t capacity) { M_BufferEnsureTotalCapacity(buf, capacity); } -size_t M_BufferGetCapacity(buf_t *buf) { +size_t M_BufferGetCapacity(const buf_t *buf) { return buf->capacity; } -size_t M_BufferGetSize(buf_t *buf) { +size_t M_BufferGetSize(const buf_t *buf) { return buf->size; } -size_t M_BufferGetCursor(buf_t *buf) { +size_t M_BufferGetCursor(const buf_t *buf) { return buf->cursor; } -char* M_BufferGetData(buf_t *buf) { +char* M_BufferGetData(const buf_t *buf) { return buf->data; } -char* M_BufferGetDataAtCursor(buf_t *buf) { +char* M_BufferGetDataAtCursor(const buf_t *buf) { return buf->data + buf->cursor; } @@ -123,11 +123,11 @@ void M_BufferEnsureTotalCapacity(buf_t *buf, size_t capacity) { } } -void M_BufferCopy(buf_t *dst, buf_t *src) { +void M_BufferCopy(buf_t *dst, const buf_t *src) { M_BufferSetData(dst, M_BufferGetData(src), M_BufferGetSize(src)); } -void M_BufferCursorCopy(buf_t *dst, buf_t *src) { +void M_BufferCursorCopy(buf_t *dst, const buf_t *src) { M_BufferWrite( dst, M_BufferGetDataAtCursor(src), @@ -210,7 +210,7 @@ bool M_BufferSeekForward(buf_t *buf, size_t count) { return true; } -uint8_t M_BufferPeek(buf_t *buf) { +uint8_t M_BufferPeek(const buf_t *buf) { return *(buf->data + buf->cursor); } @@ -339,14 +339,14 @@ void M_BufferWriteZeros(buf_t *buf, size_t count) { check_cursor(buf); } -bool M_BufferEqualsString(buf_t *buf, const char *s) { +bool M_BufferEqualsString(const buf_t *buf, const char *s) { if (strncmp(buf->data + buf->cursor, s, buf->size - buf->cursor) == 0) return true; return false; } -bool M_BufferEqualsData(buf_t *buf, const void *d, size_t size) { +bool M_BufferEqualsData(const buf_t *buf, const void *d, size_t size) { if (buf->cursor + size > buf->size) return false; @@ -464,7 +464,7 @@ bool M_BufferReadString(buf_t *buf, char *s, size_t length) { return M_BufferRead(buf, s, length); } -bool M_BufferReadStringDup(buf_t *buf, char **s) { +bool M_BufferReadStringDup(const buf_t *buf, char **s) { char *d = buf->data + buf->cursor; size_t length = strlen(d); @@ -475,7 +475,7 @@ bool M_BufferReadStringDup(buf_t *buf, char **s) { return true; } -bool M_BufferCopyString(buf_t *dst, buf_t *src) { +bool M_BufferCopyString(buf_t *dst, const buf_t *src) { char *s = src->data + src->cursor; size_t length = strlen(s); @@ -515,7 +515,7 @@ void M_BufferTruncate(buf_t *buf, size_t new_size) { buf->cursor = buf->size - 1; } -void M_BufferZero(buf_t *buf) { +void M_BufferZero(const buf_t *buf) { memset(buf->data, 0, buf->capacity); } @@ -531,7 +531,7 @@ void M_BufferFree(buf_t *buf) { buf->data = NULL; } -void M_BufferPrint(buf_t *buf) { +void M_BufferPrint(const buf_t *buf) { printf("Buffer capacity, size and cursor: [%zu, %zu, %zu].\n", buf->capacity, buf->size, @@ -548,7 +548,7 @@ void M_BufferPrint(buf_t *buf) { printf("\n"); } -void M_BufferPrintAll(buf_t *buf) { +void M_BufferPrintAll(const buf_t *buf) { printf("Buffer capacity, size and cursor: [%zu, %zu, %zu].\n", buf->capacity, buf->size, diff --git a/test/buf.h b/test/buf.h index 3b5a901..6dd5f72 100644 --- a/test/buf.h +++ b/test/buf.h @@ -37,17 +37,17 @@ buf_t* M_BufferNewWithCapacity(size_t capacity); void M_BufferInit(buf_t *buf); void M_BufferInitWithCapacity(buf_t *buf, size_t capacity); -size_t M_BufferGetCapacity(buf_t *buf); -size_t M_BufferGetSize(buf_t *buf); -size_t M_BufferGetCursor(buf_t *buf); -char* M_BufferGetData(buf_t *buf); -char* M_BufferGetDataAtCursor(buf_t *buf); +size_t M_BufferGetCapacity(const buf_t *buf); +size_t M_BufferGetSize(const buf_t *buf); +size_t M_BufferGetCursor(const buf_t *buf); +char* M_BufferGetData(const buf_t *buf); +char* M_BufferGetDataAtCursor(const buf_t *buf); void M_BufferEnsureCapacity(buf_t *buf, size_t capacity); void M_BufferEnsureTotalCapacity(buf_t *buf, size_t capacity); -void M_BufferCopy(buf_t *dst, buf_t *src); -void M_BufferCursorCopy(buf_t *dst, buf_t *src); +void M_BufferCopy(buf_t *dst, const buf_t *src); +void M_BufferCursorCopy(buf_t *dst, const buf_t *src); bool M_BufferMove(buf_t *buf, size_t dpos, size_t spos, size_t count); void M_BufferSetData(buf_t *buf, const void *data, size_t size); @@ -58,7 +58,7 @@ bool M_BufferSeek(buf_t *buf, size_t pos); bool M_BufferSeekBackward(buf_t *buf, size_t count); bool M_BufferSeekForward(buf_t *buf, size_t count); -uint8_t M_BufferPeek(buf_t *buf); +uint8_t M_BufferPeek(const buf_t *buf); void M_BufferWrite(buf_t *buf, const void *data, size_t size); void M_BufferWriteBool(buf_t *buf, bool b); @@ -91,8 +91,8 @@ void M_BufferWriteDoubles(buf_t *buf, const double *doubles, size_t count); void M_BufferWriteString(buf_t *buf, const char *string, size_t length); void M_BufferWriteZeros(buf_t *buf, size_t count); -bool M_BufferEqualsString(buf_t *buf, const char *s); -bool M_BufferEqualsData(buf_t *buf, const void *d, size_t size); +bool M_BufferEqualsString(const buf_t *buf, const char *s); +bool M_BufferEqualsData(const buf_t *buf, const void *d, size_t size); bool M_BufferRead(buf_t *buf, void *data, size_t size); bool M_BufferReadBool(buf_t *buf, bool *b); @@ -120,17 +120,17 @@ bool M_BufferReadDouble(buf_t *buf, double *d); bool M_BufferReadDoubles(buf_t *buf, double *d, size_t count); #endif bool M_BufferReadString(buf_t *buf, char *s, size_t length); -bool M_BufferReadStringDup(buf_t *buf, char **s); -bool M_BufferCopyString(buf_t *dst, buf_t *src); +bool M_BufferReadStringDup(const buf_t *buf, char **s); +bool M_BufferCopyString(buf_t *dst, const buf_t *src); void M_BufferCompact(buf_t *buf); void M_BufferTruncate(buf_t *buf, size_t new_size); -void M_BufferZero(buf_t *buf); +void M_BufferZero(const buf_t *buf); void M_BufferClear(buf_t *buf); void M_BufferFree(buf_t *buf); -void M_BufferPrint(buf_t *buf); -void M_BufferPrintAll(buf_t *buf); +void M_BufferPrint(const buf_t *buf); +void M_BufferPrintAll(const buf_t *buf); #endif