Skip to content
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

A recorded macro with "Find Next" and then "Run until the end of file" crashes Notepad++ #13342

Closed
BdR76 opened this issue Mar 13, 2023 · 2 comments
Assignees

Comments

@BdR76
Copy link
Contributor

BdR76 commented Mar 13, 2023

Description of the Issue

When you record a macro that includes a step with "Find Next", and you select "Run a Macro Multiple times" with the option "Run until the end of file", then it will get stuck in a loop and Notepad++ freezes.

Steps to Reproduce the Issue

Example file

      <mappingPart>
        <source column="v_0" />
        <destination observationCode="demin_leefstijl_0" />
      </mappingPart>
      <mappingPart>
        <source column="v_1" />
        <destination observationCode="demin_leefstijl_1" />
      </mappingPart>
      <mappingPart>
        <source column="v_2" />
        <destination observationCode="demin_leefstijl_2" />
      </mappingPart>
  1. Type the text pivotResultColumn="data" />, select & copy/cut it so it's on the clipboard
  2. Go to beginning of the example file
  3. Go to menu Macro > Start recording
  4. Ctrl+F to find next <source column="v to move the cursor to next instance
  5. Press End key to go to end of that line
  6. select last two characters />
  7. Paste pivotResultColumn="data" />
  8. Go to menu Macro > Stop recording
  9. Now go to Macro > Run a Macro Multiple times
  10. Select Run until the end of file and press OK.

Expected Behavior

The macro should run until the end of the file, so break/stop when "Find Next" wraps around to the beginning of the file, or alternatively when "Find Next" yields no more results.

Actual Behavior

The macro runs indefinitely and Notepad++ freezes

Debug Information

Notepad++ v8.4.8 (64-bit)
Build time : Dec 24 2022 - 19:40:27
Path : C:\Program Files\Notepad++\notepad++.exe
Command Line :
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows Server 2019 Standard (64-bit)
OS Version : 1809
OS Build : 17763.3887
Current ANSI codepage : 1252
Plugins :
ComparePlugin (2.0.2)
CSVLint (0.4.6.2)
CsvQuery (1.2.8)
HexEditor (0.9.12)
mimeTools (2.9)
NppConverter (4.5)
NppExport (0.4)
NPPJSONViewer (1.40)
NppMarkdownPanel (0.5)
PoorMansTSqlFormatterNppPlugin (1.6.13.31508)
RandomValuesNppPlugin (0.2.1)
XMLTools (3.1.1.13)

fyi, I encountered this while trying to manually edit a large XML file, and paste the pivotResultColumn property to the end of each source tag, but only when column name starts with the letter v.

I've found a work-around which is to first Find > Count to see how many instances the Find Next will get, for example count is 1389, and then select Run 1389 times instead of "until end of file".

Also, maybe this is somehow related to issue #12126 ?

@molsonkiko
Copy link
Contributor

molsonkiko commented Apr 5, 2023

I think there's an even easier way to make this happen:

  1. create any multi-line file
  2. start recording a macro
  3. Ctrl+F for ^ in regex mode (search for the next start of line)
  4. Stop recording macro.
  5. Do Run recorded macro and then Run until end of file.
  6. Click Run until end of file again (if the first click doesn't cause infinite loop).
  7. you will get an infinite loop.

I'm like 95% sure that the issue is somewhere in the code block that starts here but I don't know C++ so I'm apprehensive about trying to fix it myself.

@BdR76
Copy link
Contributor Author

BdR76 commented Apr 5, 2023

I'm also not that familiar with C++ but your fix looks good.

As far as I could tell this specific issue is caused somewhere in that if-statement at // eof ?, but it's all on one line and kind of hard to follow. I would change it so that each condition is on a new line, like in this example.

@donho donho self-assigned this Apr 8, 2023
molsonkiko added a commit to molsonkiko/notepad-plus-plus that referenced this issue Apr 25, 2023
fix issue notepad-plus-plus#13342
To test fix, try making file
```
f
f
```
and recording macro of find/replace form searching for f,
    then running until EOF.
This does not break any existing behavior, including:
- macros where the cursor moves towards EOF but line num doesn't change
    (those already stopped after one iteration)
- macros where line(s) are deleted with every iteration
    (even if line number doesn't change, they run until file empty)
- macros where the line number increases with each iteration
@donho donho closed this as completed in 96ff66b Jun 8, 2023
molsonkiko added a commit to molsonkiko/notepad-plus-plus that referenced this issue Jun 13, 2023
To test fix, try making file
```
f
f
```
and recording macro of find/replace form searching for f, then running until EOF.

This does not break any existing behavior, including:

   - macros where the cursor moves towards EOF but line num doesn't change (those already stopped after one iteration)
   - macros where line(s) are deleted with every iteration (even if line number doesn't change, they run until file empty)
   - macros where the line number increases with each iteration
   - macros where the cursor advances up or down with each iteration but would eventually stop anyway (those end at the correct time)

Fix notepad-plus-plus#13342, close notepad-plus-plus#13587
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants