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,6 +1481,8 @@ bool Notepad_plus::fileSave(BufferID id)
struct tm *today; struct tm *today;
today = localtime(&ltime); today = localtime(&ltime);
if (today)
{
generic_strftime(tmpbuf, temBufLen, TEXT("%Y-%m-%d_%H%M%S"), today); generic_strftime(tmpbuf, temBufLen, TEXT("%Y-%m-%d_%H%M%S"), today);
fn_bak += name; fn_bak += name;
@ -1488,8 +1490,9 @@ bool Notepad_plus::fileSave(BufferID id)
fn_bak += tmpbuf; fn_bak += tmpbuf;
fn_bak += TEXT(".bak"); 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", int res = _nativeLangSpeaker.messageBox("FileBackupFailed",
_pPublicInterface->getHSelf(), _pPublicInterface->getHSelf(),

View File

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

View File

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