diff options
Diffstat (limited to 'apps/nshlib/nsh_console.c')
-rw-r--r-- | apps/nshlib/nsh_console.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/apps/nshlib/nsh_console.c b/apps/nshlib/nsh_console.c index 410abc19d..41e992678 100644 --- a/apps/nshlib/nsh_console.c +++ b/apps/nshlib/nsh_console.c @@ -198,6 +198,8 @@ static ssize_t nsh_consolewrite(FAR struct nsh_vtbl_s *vtbl, FAR const void *buf } return ret; #else + /* REVISIT: buffer may not be NUL-terminated */ + printf("%s", buffer); return nbytes; #endif @@ -234,13 +236,30 @@ static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl, const char *fmt, ...) return ret; #else - char dest[64 * 16]; + va_list ap; + char *str; + int ret; + + /* Use avsprintf() to allocate a buffer and fill it with the formatted + * data + */ va_start(ap, fmt); - vsprintf(dest, fmt, ap); - va_end(ap); + str = NULL; + (void)avsprintf(&str, fmt, ap); + + /* Was a string allocated? */ - return printf(dest); + if (str) + { + /* Yes.. Print then free the allocated string */ + + printf("%s", str); + free(str); + } + + va_end(ap); + return 0; #endif } |