Changed DebugLog and LuaLog more reliably. (Fixed an issue that Rainmeter crashes if format parameter includes '%'.)

This commit is contained in:
spx 2010-12-15 22:03:36 +00:00
parent e2d9a6cc71
commit aa3ad1fc8f
4 changed files with 35 additions and 11 deletions

View File

@ -600,12 +600,29 @@ BOOL LSLog(int nLevel, LPCTSTR pszModule, LPCTSTR pszMessage)
return TRUE;
}
void RmNullCRTInvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved)
{
// Do nothing.
}
void DebugLog(const WCHAR* format, ... )
{
WCHAR buffer[4096];
va_list args;
va_list args;
va_start( args, format );
_vsnwprintf_s( buffer, 4096, _TRUNCATE, format, args );
_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler);
_CrtSetReportMode(_CRT_ASSERT, 0);
errno = 0;
_vsnwprintf_s( buffer, 4096, _TRUNCATE, format, args );
if (errno != 0)
{
_snwprintf_s(buffer, 4096, _TRUNCATE, L"DebugLog internal error: %s", format);
}
_set_invalid_parameter_handler(oldHandler);
LSLog(LOG_DEBUG, L"Rainmeter", buffer);
va_end(args);
}

View File

@ -52,6 +52,8 @@ BOOL RemoveBangCommand(LPCSTR command);
void TransparentBltLS (HDC dc, int nXDest, int nYDest, int nWidth, int nHeight, HDC tempDC, int nXSrc, int nYSrc, COLORREF colorTransparent);
void VarExpansion(LPSTR buffer, LPCSTR value);
void LSSetVariable(const BSTR name, const BSTR value);
void RmNullCRTInvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved);
void DebugLog(const WCHAR* message, ... );
void ResetLoggingFlag();

View File

@ -22,11 +22,6 @@
#include "MeasureTime.h"
#include "Rainmeter.h"
void MeasureTime_CRTInvalidParameterHandler(const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t pReserved)
{
// Do nothing.
}
int GetYearDay(int year, int month, int day)
{
int yearDay = 0;
@ -86,7 +81,7 @@ void CMeasureTime::TimeToString(WCHAR* buf, size_t bufLen, const WCHAR* format,
{
if (bufLen > 0)
{
_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(MeasureTime_CRTInvalidParameterHandler);
_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler);
_CrtSetReportMode(_CRT_ASSERT, 0);
errno = 0;

View File

@ -56,10 +56,20 @@ void LuaManager::ReportErrors(lua_State * L)
void LuaManager::LuaLog(const char* format, ... )
{
char buffer[4096];
va_list args;
va_start( args, format );
va_list args;
va_start( args, format );
_vsnprintf_s(buffer, 4096, _TRUNCATE, format, args );
_invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler);
_CrtSetReportMode(_CRT_ASSERT, 0);
errno = 0;
_vsnprintf_s( buffer, 4096, _TRUNCATE, format, args );
if (errno != 0)
{
_snprintf_s(buffer, 4096, _TRUNCATE, "LuaLog internal error: %s", format);
}
_set_invalid_parameter_handler(oldHandler);
#ifndef _DEBUG
// Forcing output to the Debug Output window!