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, ...) void logWrite(Log *log, LogLevel level, const char *fmt, ...)
{ {
va_list vargs; va_list vargs;
short len; int len;
#if LOG_USING_LOCK == 1 #if LOG_USING_LOCK == 1
logLock(log); logLock(log);
@ -198,6 +198,11 @@ void logWrite(Log *log, LogLevel level, const char *fmt, ...)
len = vsnprintf(logBuffer, LOG_BUFFER_SIZE - 1, fmt, vargs); len = vsnprintf(logBuffer, LOG_BUFFER_SIZE - 1, fmt, vargs);
va_end(vargs); va_end(vargs);
if (len > LOG_BUFFER_SIZE)
{
len = LOG_BUFFER_SIZE;
}
logWriteBuffer(log, level, logBuffer, len); logWriteBuffer(log, level, logBuffer, len);
#if LOG_USING_LOCK == 1 #if LOG_USING_LOCK == 1
logUnlock(log); logUnlock(log);

View File

@ -377,14 +377,18 @@ void shellPrint(Shell *shell, const char *fmt, ...)
{ {
char buffer[SHELL_PRINT_BUFFER]; char buffer[SHELL_PRINT_BUFFER];
va_list vargs; va_list vargs;
int len;
SHELL_ASSERT(shell, return); SHELL_ASSERT(shell, return);
va_start(vargs, fmt); va_start(vargs, fmt);
vsnprintf(buffer, SHELL_PRINT_BUFFER - 1, fmt, vargs); len = vsnprintf(buffer, SHELL_PRINT_BUFFER, fmt, vargs);
va_end(vargs); va_end(vargs);
if (len > SHELL_PRINT_BUFFER)
shellWriteString(shell, buffer); {
len = SHELL_PRINT_BUFFER;
}
shell->write(buffer, len);
} }
#endif #endif