From b6eab95a2536294aba9e5d7d64e01f1224eb3fcf Mon Sep 17 00:00:00 2001 From: Vigeant Date: Mon, 4 May 2020 15:39:01 -0400 Subject: [PATCH 1/2] fix test to allocate and initialize enough mem for msg Fixed test to allocate anough memory to store a nullbyte. The first test was failing on my system because msg was not terminated by a null byte and failed the strcmp in certain conditions. I also added iitialization of the heap chunk. --- .gitignore | 1 + tests/test.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 44772ff..be20139 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ tests/fixtures tests/test tests/results +*.swp diff --git a/tests/test.c b/tests/test.c index 2b8c1a7..3b29512 100644 --- a/tests/test.c +++ b/tests/test.c @@ -3,6 +3,7 @@ #include #include #include "mode-s.h" +#include #define MODE_S_DATA_LEN (16*16384) // 256k #define MODE_S_PREAMBLE_US 8 // microseconds @@ -79,9 +80,17 @@ void test(mode_s_t *self, struct mode_s_msg *mm) { MODE_S_NOTUSED(self); int j; - char *msg = (char*)malloc(mm->msgbits/4 * sizeof(char)); + char *msg = (char*)malloc(mm->msgbits/4 * sizeof(char) + 1); + memset(msg, 0x00, mm->msgbits/4 * sizeof(char) + 1); + //printf("mm->msgbits/4 = %d\n", mm->msgbits/4); for (j = 0; j < mm->msgbits/8; j++) sprintf(&msg[j*2], "%02x", mm->msg[j]); printf("validating message #%d\n", msgNo + 1); + /*printf("msg: %s, message[%d]: %s, strcmp = %d\n", msg, msgNo, messages[msgNo], strcmp(msg, messages[msgNo])); + printf("strlen(msg): %d, strlen(messages[%d]: %d\n", strlen(msg), msgNo, strlen(messages[msgNo])); + for (int i = 0; i Date: Mon, 4 May 2020 15:40:22 -0400 Subject: [PATCH 2/2] removed commented code --- tests/test.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/test.c b/tests/test.c index 3b29512..19ba7a4 100644 --- a/tests/test.c +++ b/tests/test.c @@ -82,14 +82,8 @@ void test(mode_s_t *self, struct mode_s_msg *mm) { char *msg = (char*)malloc(mm->msgbits/4 * sizeof(char) + 1); memset(msg, 0x00, mm->msgbits/4 * sizeof(char) + 1); - //printf("mm->msgbits/4 = %d\n", mm->msgbits/4); for (j = 0; j < mm->msgbits/8; j++) sprintf(&msg[j*2], "%02x", mm->msg[j]); printf("validating message #%d\n", msgNo + 1); - /*printf("msg: %s, message[%d]: %s, strcmp = %d\n", msg, msgNo, messages[msgNo], strcmp(msg, messages[msgNo])); - printf("strlen(msg): %d, strlen(messages[%d]: %d\n", strlen(msg), msgNo, strlen(messages[msgNo])); - for (int i = 0; i