Enhancement of preventing from null pointer exception of localtime

Fix #7952
This commit is contained in:
Don HO 2020-02-18 05:14:21 +01:00
parent d3cb2ceb36
commit cfa3041c4d
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
3 changed files with 24 additions and 14 deletions

View File

@ -1481,15 +1481,18 @@ bool Notepad_plus::fileSave(BufferID id)
struct tm *today;
today = localtime(&ltime);
generic_strftime(tmpbuf, temBufLen, TEXT("%Y-%m-%d_%H%M%S"), today);
if (today)
{
generic_strftime(tmpbuf, temBufLen, TEXT("%Y-%m-%d_%H%M%S"), today);
fn_bak += name;
fn_bak += TEXT(".");
fn_bak += tmpbuf;
fn_bak += TEXT(".bak");
fn_bak += name;
fn_bak += TEXT(".");
fn_bak += tmpbuf;
fn_bak += TEXT(".bak");
}
}
if (not ::CopyFile(fn, fn_bak.c_str(), FALSE))
if (!::CopyFile(fn, fn_bak.c_str(), FALSE))
{
int res = _nativeLangSpeaker.messageBox("FileBackupFailed",
_pPublicInterface->getHSelf(),

View File

@ -6950,10 +6950,12 @@ Date::Date(int nbDaysFromNow)
rawtime += (nbDaysFromNow * oneDay);
timeinfo = localtime(&rawtime);
_year = timeinfo->tm_year + 1900;
_month = timeinfo->tm_mon + 1;
_day = timeinfo->tm_mday;
if (timeinfo)
{
_year = timeinfo->tm_year + 1900;
_month = timeinfo->tm_mon + 1;
_day = timeinfo->tm_mday;
}
}
void Date::now()
@ -6963,10 +6965,12 @@ void Date::now()
time(&rawtime);
timeinfo = localtime(&rawtime);
_year = timeinfo->tm_year + 1900;
_month = timeinfo->tm_mon + 1;
_day = timeinfo->tm_mday;
if (timeinfo)
{
_year = timeinfo->tm_year + 1900;
_month = timeinfo->tm_mon + 1;
_day = timeinfo->tm_mday;
}
}

View File

@ -849,6 +849,9 @@ bool FileManager::backupCurrentBuffer()
TCHAR tmpbuf[temBufLen];
time_t ltime = time(0);
struct tm* today = localtime(&ltime);
if (!today)
return false;
generic_strftime(tmpbuf, temBufLen, TEXT("%Y-%m-%d_%H%M%S"), today);
backupFilePath += TEXT("@");