Skip to content

Commit

Permalink
Reverted: m_printf: stacksize reduced SmingHub#1097.
Browse files Browse the repository at this point in the history
Was causing instability probably due to infinite loop.
Related to SmingHub#1274.
  • Loading branch information
slav-at-attachix committed Nov 8, 2017
1 parent f09b9e7 commit 8317c97
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions Sming/system/m_printf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Descr: embedded very simple version of printf with float support
#include <stdarg.h>
#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);
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 8317c97

Please sign in to comment.