From f8ada507afd563d66451971dc41620615a7bd46f Mon Sep 17 00:00:00 2001 From: Russ Date: Sun, 10 Jan 2016 19:01:46 -0600 Subject: [PATCH] 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. --- libraries/mbed/common/RawSerial.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/mbed/common/RawSerial.cpp b/libraries/mbed/common/RawSerial.cpp index dc5db7a3fc..c3f8fdcd42 100644 --- a/libraries/mbed/common/RawSerial.cpp +++ b/libraries/mbed/common/RawSerial.cpp @@ -47,7 +47,10 @@ int RawSerial::puts(const char *str) { int RawSerial::printf(const char *format, ...) { std::va_list arg; va_start(arg, format); - int len = vsnprintf(NULL, 0, format, arg); + // ARMCC microlib does not properly handle a size of 0. + // As a workaround supply a dummy buffer with a size of 1. + char dummy_buf[1]; + int len = vsnprintf(dummy_buf, sizeof(dummy_buf), format, arg); if (len < STRING_STACK_LIMIT) { char temp[STRING_STACK_LIMIT]; vsprintf(temp, format, arg);