vfs uart tests: Avoid 1 byte heap overrun & memory leak

This commit is contained in:
Angus Gratton 2017-05-10 17:24:40 +10:00 committed by Angus Gratton
parent 895e7423a3
commit 3f68c5e988

View file

@ -50,8 +50,8 @@ TEST_CASE("can read from stdin", "[vfs]")
const size_t count = 12;
srand(count);
char* data = (char*) calloc(1, count * 8 + 1);
char* buf = (char*) calloc(1, count * 8 + 1);
char* data = (char*) calloc(1, count * 8 + 2);
char* buf = (char*) calloc(1, count * 8 + 2);
char* p = data;
for (size_t i = 0; i < count; ++i) {
p += sprintf(p, "%08x", rand());
@ -62,6 +62,9 @@ TEST_CASE("can read from stdin", "[vfs]")
size_t cb = fread(buf, 1, len, stdin);
TEST_ASSERT_EQUAL(len, cb);
TEST_ASSERT_EQUAL_UINT8_ARRAY(data, buf, len);
free(data);
free(buf);
}