Skip to content

Commit 3992712

Browse files
committed
Fix Print::printf implementation
1 parent 95598bd commit 3992712

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

cores/nRF5/Print.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,19 @@ size_t Print::println(const Printable& x)
187187
return n;
188188
}
189189

190-
int Print::printf(const char* format, ...)
190+
size_t Print::printf(const char * format, ...)
191191
{
192-
va_list va;
193-
va_start(va, format);
194-
int ret = vprintf(format, va);
195-
va_end(va);
196-
return ret;
192+
char buf[256];
193+
int len;
194+
195+
va_list ap;
196+
va_start(ap, format);
197+
198+
len = vsnprintf(buf, 256, format, ap);
199+
this->write(buf, len);
200+
201+
va_end(ap);
202+
return len;
197203
}
198204

199205
// Private Methods /////////////////////////////////////////////////////////////

cores/nRF5/Print.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Print
8383
size_t println(double, int = 2);
8484
size_t println(const Printable&);
8585
size_t println(void);
86-
int printf(const char* format, ...) __attribute__ ((format (printf, 2, 3)));
86+
size_t printf(const char* format, ...) __attribute__ ((format (printf, 2, 3)));
8787

8888
virtual void flush() { /* Empty implementation for backward compatibility */ }
8989

0 commit comments

Comments
 (0)