Skip to content

Commit 3a11349

Browse files
committed
Fix dropFiles crash on 259 chars dirs
1 parent 71773a5 commit 3a11349

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

PowerEditor/src/Notepad_plus.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4507,19 +4507,21 @@ void Notepad_plus::dropFiles(HDROP hdrop)
45074507
//else
45084508
// do not change the current Notepad++ edit-view
45094509

4510-
int filesDropped = ::DragQueryFile(hdrop, 0xffffffff, NULL, 0);
4510+
int filesDropped = ::DragQueryFileW(hdrop, 0xffffffff, NULL, 0);
45114511

45124512
vector<wstring> folderPaths;
45134513
vector<wstring> filePaths;
45144514
for (int i = 0; i < filesDropped; ++i)
45154515
{
4516-
wchar_t pathDropped[MAX_PATH];
4517-
::DragQueryFile(hdrop, i, pathDropped, MAX_PATH);
4516+
wchar_t pathDropped[MAX_PATH]{};
4517+
::DragQueryFileW(hdrop, i, pathDropped, MAX_PATH);
45184518
if (doesDirectoryExist(pathDropped))
45194519
{
4520-
size_t len = lstrlen(pathDropped);
4521-
if (len > 0 && pathDropped[len - 1] != wchar_t('\\'))
4520+
size_t len = lstrlenW(pathDropped);
4521+
if ((len > 0) && (pathDropped[len - 1] != wchar_t('\\')))
45224522
{
4523+
if (len + 1 >= MAX_PATH)
4524+
continue; // not enough space for the trailing backslash, try next
45234525
pathDropped[len] = wchar_t('\\');
45244526
pathDropped[len + 1] = wchar_t('\0');
45254527
}
@@ -4534,13 +4536,17 @@ void Notepad_plus::dropFiles(HDROP hdrop)
45344536
NppParameters& nppParam = NppParameters::getInstance();
45354537
bool isOldMode = nppParam.getNppGUI()._isFolderDroppedOpenFiles;
45364538

4537-
if (isOldMode || folderPaths.size() == 0) // old mode or new mode + only files
4539+
if ((filePaths.size() == 0) && (folderPaths.size() == 0))
4540+
{
4541+
// invalid paths, do nothing
4542+
}
4543+
else if (isOldMode || folderPaths.size() == 0) // old mode or new mode + only files
45384544
{
45394545
BufferID lastOpened = BUFFER_INVALID;
45404546
for (int i = 0; i < filesDropped; ++i)
45414547
{
4542-
wchar_t pathDropped[MAX_PATH];
4543-
::DragQueryFile(hdrop, i, pathDropped, MAX_PATH);
4548+
wchar_t pathDropped[MAX_PATH]{};
4549+
::DragQueryFileW(hdrop, i, pathDropped, MAX_PATH);
45444550
BufferID test = doOpen(pathDropped);
45454551
if (test != BUFFER_INVALID)
45464552
lastOpened = test;

0 commit comments

Comments
 (0)