Skip to content

Commit 6ebae16

Browse files
highpowerolegobolenskiy
and
olegobolenskiy
authored
fix vPrint crashes on platforms where vsnprintf invalidates va_list, in particular on epoxyduino (#40)
Co-authored-by: olegobolenskiy <[email protected]>
1 parent 2ed45e1 commit 6ebae16

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Arduino_DebugUtils.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ void Arduino_DebugUtils::print(int const debug_level, const __FlashStringHelper
130130
******************************************************************************/
131131

132132
void Arduino_DebugUtils::vPrint(char const * fmt, va_list args) {
133+
134+
va_list args_copy;
135+
va_copy(args_copy, args);
136+
133137
// calculate required buffer length
134138
int msg_buf_size = vsnprintf(nullptr, 0, fmt, args) + 1; // add one for null terminator
135139
#if __STDC_NO_VLA__ == 1
@@ -139,7 +143,8 @@ void Arduino_DebugUtils::vPrint(char const * fmt, va_list args) {
139143
char msg_buf[msg_buf_size];
140144
#endif
141145

142-
vsnprintf(msg_buf, msg_buf_size, fmt, args);
146+
vsnprintf(msg_buf, msg_buf_size, fmt, args_copy);
147+
va_end(args_copy);
143148

144149
if (_newline_on) {
145150
_debug_output_stream->println(msg_buf);

0 commit comments

Comments
 (0)