Fix crash while passing invalid buffer with NPPM_SETUNTITLEDNAME

Fix #15970, close #15975
This commit is contained in:
Alan Kilborn 2024-12-20 20:32:48 -05:00 committed by Don Ho
parent d9d7c4fbb3
commit 104cc8af73
2 changed files with 7 additions and 5 deletions

View File

@ -3140,7 +3140,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_SETUNTITLEDNAME:
{
if (!wParam || !lParam) return FALSE;
return fileRenameUntitledPluginAPI(reinterpret_cast<BufferID>(wParam), reinterpret_cast<const wchar_t*>(lParam));
}

View File

@ -2128,21 +2128,24 @@ bool Notepad_plus::fileRename(BufferID id)
bool Notepad_plus::fileRenameUntitledPluginAPI(BufferID id, const wchar_t* tabNewName)
{
if (tabNewName == nullptr) return false;
BufferID bufferID = id;
if (id == BUFFER_INVALID)
{
bufferID = _pEditView->getCurrentBufferID();
}
Buffer* buf = MainFileManager.getBufferByID(bufferID);
int bufferIndex = MainFileManager.getBufferIndexByID(bufferID);
if (bufferIndex == -1) return false;
if (!buf->isUntitled()) return false;
Buffer* buf = MainFileManager.getBufferByIndex(bufferIndex);
if (buf == nullptr || !buf->isUntitled()) return false;
// We are just going to rename the tab nothing else
// So just rename the tab and rename the backup file too if applicable
if (!tabNewName) return false;
std::wstring tabNewNameStr = tabNewName;
trim(tabNewNameStr); // No leading and tailing space allowed