diff --git a/ThirdParty/PSCommon/XnLib/Source/Win32/XnWin32Strings.cpp b/ThirdParty/PSCommon/XnLib/Source/Win32/XnWin32Strings.cpp index de869124..5532befa 100644 --- a/ThirdParty/PSCommon/XnLib/Source/Win32/XnWin32Strings.cpp +++ b/ThirdParty/PSCommon/XnLib/Source/Win32/XnWin32Strings.cpp @@ -252,9 +252,11 @@ XN_C_API XnStatus xnOSStrFormatV(XnChar* cpDestString, const XnUInt32 nDestLengt // nRes is the number of bytes written, not including NULL termination - if ((nRes == -1) || // string was truncated - (nRes == (XnInt32)nDestLength && cpDestString[nRes] != '\0')) // no space for the NULL termination + if ( nRes < 0 // encoding error + || nRes > (XnInt32)nDestLength // string was truncated + || (nRes == (XnInt32)nDestLength && cpDestString[nRes] != '\0')) // no space for the NULL termination { + *pnCharsWritten = nDestLength; return (XN_STATUS_INTERNAL_BUFFER_TOO_SMALL); } diff --git a/ThirdParty/PSCommon/XnLib/Source/XnErrorLogger.cpp b/ThirdParty/PSCommon/XnLib/Source/XnErrorLogger.cpp index 81c6b228..08c62cbf 100644 --- a/ThirdParty/PSCommon/XnLib/Source/XnErrorLogger.cpp +++ b/ThirdParty/PSCommon/XnLib/Source/XnErrorLogger.cpp @@ -44,7 +44,7 @@ namespace xnl { SingleBuffer* pBuffer = getBuffer(); - if (pBuffer->m_currentEnd > ms_bufferSize) + if (pBuffer->m_currentEnd >= ms_bufferSize) return; pBuffer->m_errorBuffer[pBuffer->m_currentEnd++] = '\t'; @@ -52,30 +52,41 @@ namespace xnl va_list args; va_start(args, cpFormat); - xnOSStrFormatV(pBuffer->m_errorBuffer+pBuffer->m_currentEnd, ms_bufferSize-pBuffer->m_currentEnd, &charsWritten, cpFormat, args); + XnStatus status = xnOSStrFormatV(pBuffer->m_errorBuffer+pBuffer->m_currentEnd, ms_bufferSize-pBuffer->m_currentEnd, &charsWritten, cpFormat, args); va_end(args); - pBuffer->m_currentEnd += charsWritten; - pBuffer->m_errorBuffer[pBuffer->m_currentEnd++] = '\n'; - pBuffer->m_errorBuffer[pBuffer->m_currentEnd] = '\0'; - + if (status == XN_STATUS_OK) + { + pBuffer->m_currentEnd += charsWritten; + pBuffer->m_errorBuffer[pBuffer->m_currentEnd++] = '\n'; + pBuffer->m_errorBuffer[pBuffer->m_currentEnd] = '\0'; + } + else + { + pBuffer->m_currentEnd += charsWritten; + } } void ErrorLogger::AppendV(const XnChar* cpFormat, va_list args) { SingleBuffer* pBuffer = getBuffer(); - if (pBuffer->m_currentEnd > ms_bufferSize) + if (pBuffer->m_currentEnd >= ms_bufferSize) return; + pBuffer->m_errorBuffer[pBuffer->m_currentEnd++] = '\t'; unsigned int charsWritten; - xnOSStrFormatV(pBuffer->m_errorBuffer+pBuffer->m_currentEnd, ms_bufferSize-pBuffer->m_currentEnd, &charsWritten, cpFormat, args); - - pBuffer->m_currentEnd += charsWritten; - pBuffer->m_errorBuffer[pBuffer->m_currentEnd++] = '\n'; - pBuffer->m_errorBuffer[pBuffer->m_currentEnd] = '\0'; - + if (xnOSStrFormatV(pBuffer->m_errorBuffer + pBuffer->m_currentEnd, ms_bufferSize - pBuffer->m_currentEnd, &charsWritten, cpFormat, args) == XN_STATUS_OK) + { + pBuffer->m_currentEnd += charsWritten; + pBuffer->m_errorBuffer[pBuffer->m_currentEnd++] = '\n'; + pBuffer->m_errorBuffer[pBuffer->m_currentEnd] = '\0'; + } + else + { + pBuffer->m_currentEnd += charsWritten; + } } ErrorLogger::ErrorLogger()