Skip to content

Commit

Permalink
Fix Print::printf implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Jan 15, 2025
1 parent 893df5c commit 4e203bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions cores/nRF5/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,19 @@ size_t Print::println(const Printable& x)
return n;
}

int Print::printf(const char* format, ...)
size_t Print::printf(const char * format, ...)
{
va_list va;
va_start(va, format);
int ret = vprintf(format, va);
va_end(va);
return ret;
char buf[256];
int len;

va_list ap;
va_start(ap, format);

len = vsnprintf(buf, 256, format, ap);
this->write(buf, len);

va_end(ap);
return len;
}

// Private Methods /////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion cores/nRF5/Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Print
size_t println(double, int = 2);
size_t println(const Printable&);
size_t println(void);
int printf(const char* format, ...) __attribute__ ((format (printf, 2, 3)));
size_t printf(const char* format, ...) __attribute__ ((format (printf, 2, 3)));

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

Expand Down

0 comments on commit 4e203bb

Please sign in to comment.