Skip to content

Path Completion not working regression #11147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
donho opened this issue Feb 7, 2022 · 5 comments
Closed

Path Completion not working regression #11147

donho opened this issue Feb 7, 2022 · 5 comments
Assignees

Comments

@donho
Copy link
Member

donho commented Feb 7, 2022

Description of the Issue

Path Completion has stopped working seems for quite moment.
It's a regression but it's not due to the removal 2GB restriction.

Steps to Reproduce the Issue

  1. Type C:\
  2. Choose menu command Edit > Auto-Completion > Path Completion or hit Ctrl-Alt-Space

Expected Behavior

Auto-completion list appears. All the sub-folder of C drive should be in the list.

Actual Behavior

Nothing happens.

Debug Information

Notepad++ v8.3 (64-bit)
Build time : Feb 5 2022 - 19:07:43
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line :
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 11 (64-bit)
OS Version : 2009
OS Build : 22000.434
Current ANSI codepage : 1252
Plugins : mimeTools.dll NppConverter.dll NppExport.dll

@donho donho self-assigned this Feb 7, 2022
@donho donho closed this as completed in 9baaef7 Feb 7, 2022
@alankilborn
Copy link
Contributor

I went on a version search to where this feature last worked.
I had to go back to v 6.9 !

@donho
Copy link
Member Author

donho commented Feb 8, 2022

I had to go back to v 6.9 !

Hmm... It seems very little users use this feature - I searched issue tracker before opening a new one, but I found nothing.

@mpheath
Copy link

mpheath commented Dec 27, 2022

@donho

Testing autocompletion and path completion is one of tests. I repeatly get these 3 msgboxes using the menu entry

---------------------------
General Exception
---------------------------
std::bad_alloc
---------------------------
OK   
---------------------------


---------------------------
Recovery initiating
---------------------------
Notepad++ will attempt to save any unsaved data. However, dataloss is very likely.
---------------------------
OK   
---------------------------


---------------------------
Recovery success
---------------------------
Notepad++ was able to successfully recover some unsaved documents, or nothing to be saved could be found.

You can find the results at :

C:\Users\Michael\AppData\Local\Temp\\N++RECOV
---------------------------
OK   
---------------------------

and then Notepad++ exits.

With Ctrl+Alt+Space I get

---------------------------
Microsoft Visual C++ Runtime Library
---------------------------

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

---------------------------
OK   
---------------------------

Click OK and crashs Notepad++.

Strange the different behaviours of menu item to keys. Probably irrelevent if fixed.


Added some printf calls to get some information.

Output:

bufSize: '260'
currentPos: '41'
startPos: '-219'

-219 for start position. Negative integer could be a possible reason for crashing.

So added more characters to get position to 3000 in the document and tried again. Path completion works.

const auto startPos = max(0, currentPos - bufSize);

If I change auto to int, no crash and no path autocomplete. If I replace currentPos and bufSize with real integers inside max(), then it works and I see autocomplete. I consider max() does not like intptr_t types as I got GCC to show error: no matching function for call to 'max(int, long long int)' with separate test code. https://cplusplus.com/reference/algorithm/max/ mentions Note that invalid arguments cause undefined behavior. So it might be undefined behaviour with types that max() cannot handle.

sizeof() displays 8 for intptr_t and comparing different byte sizes causes problems, so replace

const auto startPos = max(0, currentPos - bufSize);

with

const long long int startPos = (currentPos >= bufSize) ? (currentPos - bufSize) : 0;

works ok as it avoids directly comparing 4 byte int type with 8 byte int type. long long int is to save precision. auto works too though the compiler probably replaces it with int.

@ozone10
Copy link
Contributor

ozone10 commented Dec 27, 2022

@mpheath
Notepad++ rather than using std::max is using max macro in windows.h.
I would use intptr_t since for 64 bit it's long long (__int64) and for 32 bit int

@mpheath
Copy link

mpheath commented Dec 28, 2022

@ozone10

Thanks for the information.
Whether max or std::max, both seem to dislike comparing intptr_t with int or the compiler see the diferent types and will end the compile with warning\error.

This test works good as comparisons are only with intptr_t.

#include <iostream>     // std::cout
#include <algorithm>    // std::max
#include <shlwapi.h>    // MAX_PATH

int main () {
	const intptr_t bufSize = MAX_PATH;
	const intptr_t currentPos = 41;
	const intptr_t zero = 0;
	const auto startPos = std::max(zero, currentPos - bufSize);
	std::cout << startPos << '\n';
}

In AutoCompletion.cpp, changing

const auto startPos = max(0, currentPos - bufSize);

to

const auto startPos = (currentPos > bufSize) ? (currentPos - bufSize) : 0;

or

const intptr_t startPos = (currentPos > bufSize) ? (currentPos - bufSize) : 0;

or

const intptr_t zero = 0;
const auto startPos = max(zero, currentPos - bufSize);

works for me.

If you can trust the compiler, then auto seems OK, though it should be intptr_t if the compiler gets it right unless I am fail to understand.

I changed the ternary >= to > as doing currentPos - bufSize seems meaningless to return 0. The ternary has the benefit of not needing the zero to be declared and assigned a value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants