Skip to content

Commit f8ada50

Browse files
committed
Fix RawSerial when used with ARMCC microlib
The function vsnprintf does not properly handle a size of zero for the destination buffer, and will write data to it. If the buffer is set to null this will cause a hardfault. This patch adds a workaround for this bug by using a buffer of size 1.
1 parent 8b10c2a commit f8ada50

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

libraries/mbed/common/RawSerial.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ int RawSerial::puts(const char *str) {
4747
int RawSerial::printf(const char *format, ...) {
4848
std::va_list arg;
4949
va_start(arg, format);
50-
int len = vsnprintf(NULL, 0, format, arg);
50+
// ARMCC microlib does not properly handle a size of 0.
51+
// As a workaround supply a dummy buffer with a size of 1.
52+
char dummy_buf[1];
53+
int len = vsnprintf(dummy_buf, sizeof(dummy_buf), format, arg);
5154
if (len < STRING_STACK_LIMIT) {
5255
char temp[STRING_STACK_LIMIT];
5356
vsprintf(temp, format, arg);

0 commit comments

Comments
 (0)