Skip to content

Commit c013a0e

Browse files
committed
fix(printf): fctprintf() must not append null terminator
Fixes #39, references #19
1 parent d974b16 commit c013a0e

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

printf.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,10 @@ static inline void _out_char(char character, void* buffer, size_t idx, size_t ma
134134
static inline void _out_fct(char character, void* buffer, size_t idx, size_t maxlen)
135135
{
136136
(void)idx; (void)maxlen;
137-
// buffer is the output fct pointer
138-
((out_fct_wrap_type*)buffer)->fct(character, ((out_fct_wrap_type*)buffer)->arg);
137+
if (character) {
138+
// buffer is the output fct pointer
139+
((out_fct_wrap_type*)buffer)->fct(character, ((out_fct_wrap_type*)buffer)->arg);
140+
}
139141
}
140142

141143

test/test_suite.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ TEST_CASE("fctprintf", "[]" ) {
6969
printf_idx = 0U;
7070
memset(printf_buffer, 0xCC, 100U);
7171
test::fctprintf(&_out_fct, nullptr, "This is a test of %X", 0x12EFU);
72-
REQUIRE(!strcmp(printf_buffer, "This is a test of 12EF"));
72+
REQUIRE(!strncmp(printf_buffer, "This is a test of 12EF", 22U));
73+
REQUIRE(printf_buffer[22] == (char)0xCC);
7374
}
7475

7576

0 commit comments

Comments
 (0)