I have an error logging mechanism, which constructs a buffer using vsntprintf_s
.
Unfortunately it so happens that if it sees a "%"
symbol, then there is an exception while constructing the buffer.
TCHAR szBuffer[2000];
if (lpszFormat != NULL)
_vsntprintf_s(szBuffer, _countof(szBuffer), lpszFormat, args);
Whole function -
bool someFunction::TraceLog (LPCTSTR lpszFormat, ...)
{
va_list args = nullptr;
va_start (args, lpszFormat);
TCHAR szBuffer[2000];
if (lpszFormat != NULL)
_vsntprintf_s(szBuffer, _countof(szBuffer), lpszFormat, args);
else
_tcsncpy_s (szBuffer, _T("NULL format for TraceGen"), _TRUNCATE);
}
where, if the input string, lpszFormat
contains a '%' it fails. The "%"
is not meant to be an operator, but is rather for something within the string itself. E.g. Test%Test
What can be the best way to handle this?