Skip to content

Commit d20ce63

Browse files
committed
Merge pull request #463 from toyowata/master
[Common] Fixed crash issue in RawSerial::printf for uARM
2 parents 74958e0 + d05b7f5 commit d20ce63

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

libraries/mbed/common/RawSerial.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ int RawSerial::puts(const char *str) {
4747
int RawSerial::printf(const char *format, ...) {
4848
std::va_list arg;
4949
va_start(arg, format);
50+
#if defined(__MICROLIB) && defined(__ARMCC_VERSION) // with microlib and ARM compiler
51+
char *temp;
52+
temp = (char*)alloca(STRING_STACK_LIMIT);
53+
vsprintf(temp, format, arg);
54+
puts(temp);
55+
int len = strlen(temp);
56+
#else
5057
int len = vsnprintf(NULL, 0, format, arg);
5158
if (len < STRING_STACK_LIMIT) {
5259
char temp[STRING_STACK_LIMIT];
@@ -58,6 +65,7 @@ int RawSerial::printf(const char *format, ...) {
5865
puts(temp);
5966
delete[] temp;
6067
}
68+
#endif
6169
va_end(arg);
6270
return len;
6371
}

0 commit comments

Comments
 (0)