From 273e6f9ba436212cfb230462029a7ed751f5cb6b Mon Sep 17 00:00:00 2001 From: Marco Studerus Date: Mon, 30 Apr 2018 22:47:01 +0200 Subject: [PATCH] [nrf52840] check return value of vsnprintf in otPlatLog (#2691) --- examples/platforms/nrf52840/logging.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/platforms/nrf52840/logging.c b/examples/platforms/nrf52840/logging.c index 00eab1353..b9682d325 100644 --- a/examples/platforms/nrf52840/logging.c +++ b/examples/platforms/nrf52840/logging.c @@ -145,6 +145,7 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat (void)aLogRegion; uint16_t length = 0; + int charsWritten; char logString[LOG_PARSE_BUFFER_SIZE + 1]; otEXPECT(sLogInitialized == true); @@ -159,7 +160,9 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat // Parse user string. va_list paramList; va_start(paramList, aFormat); - length += vsnprintf(&logString[length], (LOG_PARSE_BUFFER_SIZE - length), aFormat, paramList); + charsWritten = vsnprintf(&logString[length], (LOG_PARSE_BUFFER_SIZE - length), aFormat, paramList); + otEXPECT(charsWritten >= 0); + length += charsWritten; if (length > LOG_PARSE_BUFFER_SIZE) {