Fixed a possible stack overflow in decode_date_str() function + set debugger flags when creating DEBUG build.
This commit is contained in:
parent
a0707809f5
commit
4d41d882da
@ -127,7 +127,7 @@
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(QTDIR)\lib</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(QTDIR)\lib;$(SolutionDir)\..\Prerequisites\VisualLeakDetector\lib\Win32</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>QtCored4.lib;QtGuid4.lib;Psapi.lib;Sensapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
@ -156,7 +156,7 @@
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(QTDIR)\lib</AdditionalLibraryDirectories>
|
||||
<AdditionalLibraryDirectories>$(QTDIR)\lib;$(SolutionDir)\..\Prerequisites\VisualLeakDetector\lib\Win32</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>QtCore4.lib;QtGui4.lib;Psapi.lib;Sensapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
|
@ -41,6 +41,9 @@
|
||||
#include <ctime>
|
||||
#include <process.h>
|
||||
|
||||
//VLD
|
||||
#include <vld.h>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Random Support
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -327,11 +330,15 @@ void MUtils::natural_string_sort(QStringList &list, const bool bIgnoreCase)
|
||||
// SELF-TEST
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int MUtils::Internal::selfTest(const char *const date, const bool debug)
|
||||
int MUtils::Internal::selfTest(const char *const buildKey, const bool debug)
|
||||
{
|
||||
if(strncmp(date, __DATE__"@"__TIME__, 14) || (MUTILS_DEBUG != debug))
|
||||
static const bool MY_DEBUG_FLAG = MUTILS_DEBUG;
|
||||
static const char *const MY_BUILD_KEY = __DATE__"@"__TIME__;
|
||||
|
||||
if(strncmp(buildKey, MY_BUILD_KEY, 14) || (MY_DEBUG_FLAG != debug))
|
||||
{
|
||||
MUtils::OS::system_message_err(L"MUtils", L"FATAL ERROR: MUtils library version mismatch detected!");
|
||||
MUtils::OS::system_message_wrn(L"MUtils", L"Please re-build the complete solution in order to fix this issue!");
|
||||
abort();
|
||||
}
|
||||
return 0;
|
||||
|
@ -94,7 +94,10 @@ static int startup_helper(int &argc, char **argv, MUtils::Startup::main_function
|
||||
int MUtils::Startup::startup(int &argc, char **argv, main_function_t *const entry_point)
|
||||
{
|
||||
int iResult = -1;
|
||||
#if 1||(MUTILS_DEBUG)
|
||||
#if (MUTILS_DEBUG)
|
||||
#ifdef _MSC_VER
|
||||
_CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF || _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG));
|
||||
#endif //_MSCVER
|
||||
iResult = startup_main(argc, argv, entry_point);
|
||||
#else //MUTILS_DEBUG
|
||||
#ifdef _MSC_VER
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
static const char *g_months_lut[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
static int month2int(const char *str)
|
||||
static int month_str2int(const char *str)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@ -55,16 +55,18 @@ static int month2int(const char *str)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const QDate decode_date_str(const char *const date_str)
|
||||
static const QDate decode_date_str(const char *const date_str) //Mmm dd yyyy
|
||||
{
|
||||
bool ok = true;
|
||||
int date[3] = {0, 0, 0};
|
||||
char month_s[4];
|
||||
char buffer[12];
|
||||
|
||||
ok = ok && (_snscanf(&date_str[0x0], 3, "%s", &month_s) == 1);
|
||||
ok = ok && ((date[1] = month2int(month_s)) > 0);
|
||||
ok = ok && (_snscanf(&date_str[0x4], 2, "%d", &date[2]) == 1);
|
||||
ok = ok && (_snscanf(&date_str[0x7], 4, "%d", &date[0]) == 1);
|
||||
strcpy_s(buffer, 12, date_str);
|
||||
buffer[3] = buffer[6] = '\0';
|
||||
|
||||
ok = ok && ((date[1] = month_str2int(&buffer[0])) > 0);
|
||||
ok = ok && (sscanf_s(&buffer[4], "%d", &date[2]) == 1);
|
||||
ok = ok && (sscanf_s(&buffer[7], "%d", &date[0]) == 1);
|
||||
|
||||
if(!ok)
|
||||
{
|
||||
@ -75,14 +77,18 @@ static const QDate decode_date_str(const char *const date_str)
|
||||
return QDate(date[0], date[1], date[2]);
|
||||
}
|
||||
|
||||
static const QTime decode_time_str(const char *const time_str)
|
||||
static const QTime decode_time_str(const char *const time_str) //hh:mm:ss
|
||||
{
|
||||
bool ok = true;
|
||||
int time[3] = {0, 0, 0};
|
||||
char buffer[9];
|
||||
|
||||
ok = ok && (_snscanf(&time_str[0x0], 2, "%d", &time[0]) == 1);
|
||||
ok = ok && (_snscanf(&time_str[0x3], 2, "%d", &time[1]) == 1);
|
||||
ok = ok && (_snscanf(&time_str[0x6], 2, "%d", &time[2]) == 1);
|
||||
strcpy_s(buffer, 9, time_str);
|
||||
buffer[2] = buffer[5] = '\0';
|
||||
|
||||
ok = ok && (sscanf_s(&time_str[0], "%d", &time[0]) == 1);
|
||||
ok = ok && (sscanf_s(&time_str[3], "%d", &time[1]) == 1);
|
||||
ok = ok && (sscanf_s(&time_str[6], "%d", &time[2]) == 1);
|
||||
|
||||
if(!ok)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user