Skip to content

Remove hardcoded line length limit #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/Arduino_DebugUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,27 @@ void Arduino_DebugUtils::print(int const debug_level, const __FlashStringHelper
******************************************************************************/

void Arduino_DebugUtils::vPrint(char const * fmt, va_list args) {
static size_t const MSG_BUF_SIZE = 120;
char msg_buf[MSG_BUF_SIZE] = {0};
// calculate required buffer length
int msg_buf_size = vsnprintf(nullptr, 0, fmt, args) + 1; // add one for null terminator
#if __STDC_NO_VLA__ == 1
// in the rare case where VLA is not allowed by compiler, fall back on heap-allocated memory
char * msg_buf = new char[msg_buf_size];
#else
char msg_buf[msg_buf_size];
#endif

vsnprintf(msg_buf, MSG_BUF_SIZE, fmt, args);
vsnprintf(msg_buf, msg_buf_size, fmt, args);

if (_newline_on) {
_debug_output_stream->println(msg_buf);
} else {
_debug_output_stream->print(msg_buf);
}

#if __STDC_NO_VLA__ == 1
// remember to clean up memory
delete[] msg_buf;
#endif
}

void Arduino_DebugUtils::printTimestamp()
Expand Down