mirror of
https://github.com/espressif/openthread.git
synced 2026-09-17 22:50:07 +00:00
NcpUart: Adjust vsnprinf() returned charsWritten in case of overflow (#1064)
This commit is contained in:
committed by
Jonathan Hui
parent
bc8b1a4cd1
commit
2f7f3f0b99
@@ -1232,7 +1232,7 @@ const char *otLogRegionToString(otLogRegion aRegion);
|
||||
otPlatLog( \
|
||||
aLogLevel, \
|
||||
aRegion, \
|
||||
"[%s]%s: " aFormat OPENTHREAD_CONFIG_LOG_SUFFIX, \
|
||||
"[%s]%s: " aFormat OPENTHREAD_CONFIG_LOG_SUFFIX, \
|
||||
otLogLevelToString(aLogLevel), \
|
||||
otLogRegionToString(aRegion), \
|
||||
## __VA_ARGS__ \
|
||||
@@ -1247,7 +1247,7 @@ const char *otLogRegionToString(otLogRegion aRegion);
|
||||
otPlatLog( \
|
||||
aLogLevel, \
|
||||
aRegion, \
|
||||
"[%s]: " aFormat OPENTHREAD_CONFIG_LOG_SUFFIX, \
|
||||
"[%s]: " aFormat OPENTHREAD_CONFIG_LOG_SUFFIX, \
|
||||
otLogLevelToString(aLogLevel), \
|
||||
## __VA_ARGS__ \
|
||||
)
|
||||
|
||||
@@ -279,6 +279,11 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat
|
||||
va_start(args, aFormat);
|
||||
if ((charsWritten = vsnprintf(logString, sizeof(logString), aFormat, args)) > 0)
|
||||
{
|
||||
if (charsWritten > static_cast<int>(sizeof(logString) - 1))
|
||||
{
|
||||
charsWritten = static_cast<int>(sizeof(logString) - 1);
|
||||
}
|
||||
|
||||
otNcpStreamWrite(0, reinterpret_cast<uint8_t*>(logString), charsWritten);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
Reference in New Issue
Block a user