From 38ddd32ac51c7a34b6f8f47c9571c45d4dbf9bef Mon Sep 17 00:00:00 2001 From: Don HO Date: Fri, 15 Jul 2016 02:18:01 +0200 Subject: [PATCH] Added some error checking during file saving. Closese #1930 --- PowerEditor/src/NppIO.cpp | 11 +++++++++-- PowerEditor/src/ScitillaComponent/Buffer.cpp | 14 +++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 9fdc1e3f..bcc46373 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -1176,7 +1176,11 @@ bool Notepad_plus::fileSave(BufferID id) fn_bak = fn; } fn_bak += TEXT(".bak"); - ::CopyFile(fn, fn_bak.c_str(), FALSE); + + if (not ::CopyFile(fn, fn_bak.c_str(), FALSE)) + { + return false; + } } else if (backup == bak_verbose) { @@ -1221,7 +1225,10 @@ bool Notepad_plus::fileSave(BufferID id) fn_dateTime_bak += tmpbuf; fn_dateTime_bak += TEXT(".bak"); - ::CopyFile(fn, fn_dateTime_bak.c_str(), FALSE); + if (not ::CopyFile(fn, fn_dateTime_bak.c_str(), FALSE)) + { + return false; + } } return doSave(bufferID, buf->getFullPathName(), false); } diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 7cc14592..f3c7ca64 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -805,22 +805,30 @@ bool FileManager::backupCurrentBuffer() // Synchronization // This method is called from 2 differents place, so synchronization is important HANDLE writeEvent = ::OpenEvent(EVENT_ALL_ACCESS, TRUE, TEXT("nppWrittingEvent")); - if (!writeEvent) + if (not writeEvent) { // no thread yet, create a event with non-signaled, to block all threads writeEvent = ::CreateEvent(NULL, TRUE, FALSE, TEXT("nppWrittingEvent")); + if (not writeEvent) + { + printStr(TEXT("CreateEvent problem in backupCurrentBuffer()!")); + return false; + } } else { if (::WaitForSingleObject(writeEvent, INFINITE) != WAIT_OBJECT_0) { - // problem!!! printStr(TEXT("WaitForSingleObject problem in backupCurrentBuffer()!")); return false; } // unlocled here, set to non-signaled state, to block all threads - ::ResetEvent(writeEvent); + if (not ::ResetEvent(writeEvent)) + { + printStr(TEXT("ResetEvent problem in backupCurrentBuffer()!")); + return false; + } } UniMode mode = buffer->getUnicodeMode();