Skip to content

Commit b6eab95

Browse files
committed
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.
1 parent e82c6fa commit b6eab95

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
tests/fixtures
33
tests/test
44
tests/results
5+
*.swp

tests/test.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <pthread.h>
44
#include <assert.h>
55
#include "mode-s.h"
6+
#include <time.h>
67

78
#define MODE_S_DATA_LEN (16*16384) // 256k
89
#define MODE_S_PREAMBLE_US 8 // microseconds
@@ -79,9 +80,17 @@ void test(mode_s_t *self, struct mode_s_msg *mm) {
7980
MODE_S_NOTUSED(self);
8081
int j;
8182

82-
char *msg = (char*)malloc(mm->msgbits/4 * sizeof(char));
83+
char *msg = (char*)malloc(mm->msgbits/4 * sizeof(char) + 1);
84+
memset(msg, 0x00, mm->msgbits/4 * sizeof(char) + 1);
85+
//printf("mm->msgbits/4 = %d\n", mm->msgbits/4);
8386
for (j = 0; j < mm->msgbits/8; j++) sprintf(&msg[j*2], "%02x", mm->msg[j]);
8487
printf("validating message #%d\n", msgNo + 1);
88+
/*printf("msg: %s, message[%d]: %s, strcmp = %d\n", msg, msgNo, messages[msgNo], strcmp(msg, messages[msgNo]));
89+
printf("strlen(msg): %d, strlen(messages[%d]: %d\n", strlen(msg), msgNo, strlen(messages[msgNo]));
90+
for (int i = 0; i<strlen(msg); i++){
91+
printf("msg[%d]: %x, messages[%d][%d]: %x\n", i, msg[i], msgNo, i, messages[msgNo][i]);
92+
}*/
93+
fflush(stdout);
8594

8695
assert(strcmp(msg, messages[msgNo++]) == 0);
8796
}

0 commit comments

Comments
 (0)