1
0
mirror of https://github.com/NevermindZZT/letter-shell.git synced 2025-01-21 10:02:54 +08:00

修复 对 vsnprintf 函数的错误用法

This commit is contained in:
Letter 2023-05-27 08:51:58 +00:00
parent 04d9ed7bce
commit b10dd14273
2 changed files with 13 additions and 4 deletions

View File

@ -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);

View File

@ -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