mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-28 16:24:27 +02:00
Fix crash while passing invalid buffer with NPPM_SETUNTITLEDNAME
Fix #15970, close #15975
This commit is contained in:
parent
d9d7c4fbb3
commit
104cc8af73
@ -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));
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user