Skip to content

Commit

Permalink
fix(printf): fctprintf() must not append null terminator
Browse files Browse the repository at this point in the history
Fixes #39, references #19
  • Loading branch information
mpaland committed Jan 16, 2019
1 parent d974b16 commit c013a0e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ static inline void _out_char(char character, void* buffer, size_t idx, size_t ma
static inline void _out_fct(char character, void* buffer, size_t idx, size_t maxlen)
{
(void)idx; (void)maxlen;
// buffer is the output fct pointer
((out_fct_wrap_type*)buffer)->fct(character, ((out_fct_wrap_type*)buffer)->arg);
if (character) {
// buffer is the output fct pointer
((out_fct_wrap_type*)buffer)->fct(character, ((out_fct_wrap_type*)buffer)->arg);
}
}


Expand Down
3 changes: 2 additions & 1 deletion test/test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ TEST_CASE("fctprintf", "[]" ) {
printf_idx = 0U;
memset(printf_buffer, 0xCC, 100U);
test::fctprintf(&_out_fct, nullptr, "This is a test of %X", 0x12EFU);
REQUIRE(!strcmp(printf_buffer, "This is a test of 12EF"));
REQUIRE(!strncmp(printf_buffer, "This is a test of 12EF", 22U));
REQUIRE(printf_buffer[22] == (char)0xCC);
}


Expand Down

0 comments on commit c013a0e

Please sign in to comment.