From 15561c8d6903b9d4a7111fe397c1132211ae075d Mon Sep 17 00:00:00 2001 From: gszo123 Date: Sun, 29 May 2016 17:55:59 +0200 Subject: [PATCH] Fix file saving crash due to invald buffer While trying to save a untitled empty document, user could open a existing file that erases the untitled document's buffer, then save action make Notepad++ crash: https://www.youtube.com/watch?v=balHtvy4Toc Fixes #1857, Closes #1904 --- PowerEditor/src/NppIO.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 7a5cc005..8feb0362 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -453,6 +453,18 @@ bool Notepad_plus::doReload(BufferID id, bool alert) bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy) { + const int index = MainFileManager->getBufferIndexByID(id); + if (index == -1) + { + _nativeLangSpeaker.messageBox("BufferInvalidWarning", + _pPublicInterface->getHSelf(), + TEXT("Cannot save: Buffer is invalid."), + TEXT("Save failed"), + MB_OK | MB_ICONWARNING); + + return false; + } + SCNotification scnN; // Notify plugins that current file is about to be saved if (!isCopy)