Skip to content

Commit 6300e09

Browse files
committed
Remove hardcoded line limit
1 parent 9692324 commit 6300e09

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Diff for: src/Arduino_DebugUtils.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,27 @@ void Arduino_DebugUtils::print(int const debug_level, const __FlashStringHelper
102102
******************************************************************************/
103103

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

108-
vsnprintf(msg_buf, MSG_BUF_SIZE, fmt, args);
114+
vsnprintf(msg_buf, msg_buf_size, fmt, args);
109115

110116
if (_newline_on) {
111117
_debug_output_stream->println(msg_buf);
112118
} else {
113119
_debug_output_stream->print(msg_buf);
114120
}
121+
122+
#if __STDC_NO_VLA__ == 1
123+
// remember to clean up memory
124+
delete[] msg_buf;
125+
#endif
115126
}
116127

117128
void Arduino_DebugUtils::printTimestamp()

0 commit comments

Comments
 (0)