From 85b8bcd01eac53d54a9df54eb804da68a796d90d Mon Sep 17 00:00:00 2001 From: slaff Date: Wed, 8 Nov 2017 03:45:53 -0800 Subject: [PATCH] Reverted: m_printf: stacksize reduced #1097. (#1279) Was causing instability probably due to infinite loop. Related to #1274. --- Sming/system/m_printf.cpp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Sming/system/m_printf.cpp b/Sming/system/m_printf.cpp index 507f873e00..03971661ab 100644 --- a/Sming/system/m_printf.cpp +++ b/Sming/system/m_printf.cpp @@ -9,7 +9,7 @@ Descr: embedded very simple version of printf with float support #include #include "osapi.h" -#define INITIAL_BUFFSIZE 128 +#define MPRINTF_BUF_SIZE 256 static void defaultPrintChar(uart_t *uart, char c) { return uart_tx_one_char(c); @@ -62,25 +62,27 @@ int m_snprintf(char* buf, int length, const char *fmt, ...) return n; } -int m_vprintf(const char *fmt, va_list va) +int m_vprintf ( const char * format, va_list arg ) { - size_t size = INITIAL_BUFFSIZE - 1; - - // need to retry if size is not big enough - while (1) { - char buffer[size + 1]; - size_t sz = m_vsnprintf(buffer, sizeof(buffer), fmt, va); - if (sz > size) { - size = sz; - continue; - } + if(!cbc_printchar) + { + return 0; + } - const char *p = buffer; - while (char c = *p++) { - cbc_printchar(cbc_printchar_uart, c); - } - return sz; - } + char buf[MPRINTF_BUF_SIZE], *p; + + int n = 0; + m_vsnprintf(buf, sizeof(buf), format, arg); + + p = buf; + while (p && n < sizeof(buf) && *p) + { + cbc_printchar(cbc_printchar_uart, *p); + n++; + p++; + } + + return n; } /**