Fix crash on opening file with wild card characters · notepad-plus-plus/notepad-plus-plus@db33083

File tree

2 files changed

lines changed

  • PowerEditor/src/ScintillaComponent

2 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -643,16 +643,22 @@ void FileManager::closeBuffer(BufferID id, ScintillaEditView * identifier)

643643

BufferID FileManager::loadFile(const TCHAR* filename, Document doc, int encoding, const TCHAR* backupFileName, FILETIME fileNameTimestamp)

644644

{

645645

//Get file size

646+

int64_t fileSize = -1;

646647

const TCHAR* pPath = filename;

647648

if (!::PathFileExists(pPath))

649+

{

648650

pPath = backupFileName;

649-

FILE* fp = generic_fopen(pPath, TEXT("rb"));

650-

if (!fp)

651-

return BUFFER_INVALID;

652-
653-

_fseeki64(fp, 0, SEEK_END);

654-

int64_t fileSize = _ftelli64(fp);

655-

fclose(fp);

651+

}

652+

if (pPath)

653+

{

654+

FILE* fp = generic_fopen(pPath, TEXT("rb"));

655+

if (fp)

656+

{

657+

_fseeki64(fp, 0, SEEK_END);

658+

fileSize = _ftelli64(fp);

659+

fclose(fp);

660+

}

661+

}

656662
657663

// * the auto-completion feature will be disabled for large files

658664

// * the session snapshotsand periodic backups feature will be disabled for large files

Original file line numberDiff line numberDiff line change

@@ -20,7 +20,7 @@ typedef size_t Sci_PositionU;

2020
2121
2222

// For Sci_CharacterRange which is defined as long to be compatible with Win32 CHARRANGE

23-

typedef long Sci_PositionCR;

23+

typedef intptr_t Sci_PositionCR;

2424
2525

#ifdef _WIN32

2626

#define SCI_METHOD __stdcall