From f20170406ee892f39ed68627747180427123bf3e Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Tue, 29 May 2012 19:43:24 +0300 Subject: [PATCH] Tweaks --- Library/Litestep.cpp | 8 ++++---- Library/Measure.cpp | 2 +- Library/MeasureNet.cpp | 23 ++++++++++------------- Library/lua/LuaManager.cpp | 19 ++++++++++--------- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/Library/Litestep.cpp b/Library/Litestep.cpp index 3e70b6d3..1b0e175d 100644 --- a/Library/Litestep.cpp +++ b/Library/Litestep.cpp @@ -277,19 +277,19 @@ void Log(int nLevel, const WCHAR* message) void LogWithArgs(int nLevel, const WCHAR* format, ...) { - WCHAR* buffer = new WCHAR[4096]; + WCHAR* buffer = new WCHAR[1024]; va_list args; - va_start( args, format ); + va_start(args, format); _invalid_parameter_handler oldHandler = _set_invalid_parameter_handler(RmNullCRTInvalidParameterHandler); _CrtSetReportMode(_CRT_ASSERT, 0); errno = 0; - _vsnwprintf_s(buffer, 4096, _TRUNCATE, format, args); + _vsnwprintf_s(buffer, 1024, _TRUNCATE, format, args); if (errno != 0) { nLevel = LOG_ERROR; - _snwprintf_s(buffer, 4096, _TRUNCATE, L"LogWithArgs internal error: %s", format); + _snwprintf_s(buffer, 1024, _TRUNCATE, L"Internal error: %s", format); } _set_invalid_parameter_handler(oldHandler); diff --git a/Library/Measure.cpp b/Library/Measure.cpp index b7de3416..9b97457b 100644 --- a/Library/Measure.cpp +++ b/Library/Measure.cpp @@ -254,7 +254,7 @@ const WCHAR* CMeasure::CheckSubstitute(const WCHAR* buffer) if (re == NULL) { MakePlainSubstitute(str, i); - Log(LOG_NOTICE, ConvertToWide(error).c_str()); + LogWithArgs(LOG_NOTICE, L"%S", error); } else { diff --git a/Library/MeasureNet.cpp b/Library/MeasureNet.cpp index 1bbe4a28..7ab1444b 100644 --- a/Library/MeasureNet.cpp +++ b/Library/MeasureNet.cpp @@ -205,37 +205,34 @@ void CMeasureNet::UpdateIFTable() for (size_t i = 0; i < c_NumOfTables; ++i) { - std::string desc((char*)ifTable->table[i].bDescr, ifTable->table[i].dwDescrLen); - - std::wstring type; + const WCHAR* type = L""; switch (ifTable->table[i].dwType) { case IF_TYPE_ETHERNET_CSMACD: - type += L"Ethernet"; + type = L"Ethernet"; break; case IF_TYPE_PPP: - type += L"PPP"; + type = L"PPP"; break; case IF_TYPE_SOFTWARE_LOOPBACK: - type += L"Loopback"; + type = L"Loopback"; break; case IF_TYPE_IEEE80211: - type += L"IEEE802.11"; + type = L"IEEE802.11"; break; case IF_TYPE_TUNNEL: - type += L"Tunnel"; + type = L"Tunnel"; break; case IF_TYPE_IEEE1394: - type += L"IEEE1394"; + type = L"IEEE1394"; break; default: - type += L"Other"; + type = L"Other"; break; } - LogWithArgs(LOG_DEBUG, L"%i: %s", (int)i + 1, ConvertToWide(desc.c_str()).c_str()); - LogWithArgs(LOG_DEBUG, L" Type=%s(%i)", - type.c_str(), ifTable->table[i].dwType); + LogWithArgs(LOG_DEBUG, L"%i: %.*S", (int)i + 1, ifTable->table[i].dwDescrLen, (char*)ifTable->table[i].bDescr); + LogWithArgs(LOG_DEBUG, L" Type=%s(%i)", type, ifTable->table[i].dwType); } Log(LOG_DEBUG, L"------------------------------"); } diff --git a/Library/lua/LuaManager.cpp b/Library/lua/LuaManager.cpp index 7b16d566..a193625f 100644 --- a/Library/lua/LuaManager.cpp +++ b/Library/lua/LuaManager.cpp @@ -76,21 +76,22 @@ void LuaManager::Finalize() void LuaManager::ReportErrors(lua_State* L) { - std::string error = lua_tostring(L, -1); + const char* error = lua_tostring(L, -1); lua_pop(L, 1); + const char* pos = error + 4; // Skip the drive + // Get rid of everything up to the filename - std::string::size_type pos = 4; // Skip the drive - pos = error.find_first_of(':', pos); - pos = error.find_last_of('\\', pos); - if (pos != std::string::npos) + while (*pos != ':') { - error.erase(0, ++pos); + if (*pos == '\\') + { + error = pos + 1; + } + ++pos; } - std::wstring str = L"Script: "; - str += ConvertToWide(error.c_str()); - Log(LOG_ERROR, str.c_str()); + LogWithArgs(LOG_ERROR, L"Script: %S", error); } void LuaManager::PushWide(lua_State* L, const WCHAR* str)