diff --git a/extensions/log/log.c b/extensions/log/log.c index 054e198..99afc86 100644 --- a/extensions/log/log.c +++ b/extensions/log/log.c @@ -189,7 +189,7 @@ static void logWriteBuffer(Log *log, LogLevel level, char *buffer, short len) void logWrite(Log *log, LogLevel level, const char *fmt, ...) { va_list vargs; - short len; + int len; #if LOG_USING_LOCK == 1 logLock(log); @@ -198,6 +198,11 @@ void logWrite(Log *log, LogLevel level, const char *fmt, ...) len = vsnprintf(logBuffer, LOG_BUFFER_SIZE - 1, fmt, vargs); va_end(vargs); + if (len > LOG_BUFFER_SIZE) + { + len = LOG_BUFFER_SIZE; + } + logWriteBuffer(log, level, logBuffer, len); #if LOG_USING_LOCK == 1 logUnlock(log); diff --git a/src/shell.c b/src/shell.c index a73349a..fde119c 100644 --- a/src/shell.c +++ b/src/shell.c @@ -377,14 +377,18 @@ void shellPrint(Shell *shell, const char *fmt, ...) { char buffer[SHELL_PRINT_BUFFER]; va_list vargs; + int len; SHELL_ASSERT(shell, return); va_start(vargs, fmt); - vsnprintf(buffer, SHELL_PRINT_BUFFER - 1, fmt, vargs); + len = vsnprintf(buffer, SHELL_PRINT_BUFFER, fmt, vargs); va_end(vargs); - - shellWriteString(shell, buffer); + if (len > SHELL_PRINT_BUFFER) + { + len = SHELL_PRINT_BUFFER; + } + shell->write(buffer, len); } #endif