Page 1 of 1

Why does this crash TextPad?

Posted: Wed Aug 03, 2022 11:47 am
by terrypin
The following removes the right hand bracket from lines like these:
96)
106)
229)

Find what: \)
Replace with: (empty)
(Regex enabled)

But on my first attempt I added an unnecessary '?', i.e:
Find what: \)?

Why did that not only fail to work but consistently crashed TP?

Posted: Wed Aug 03, 2022 1:02 pm
by bbadmin
We can't reproduce this behaviour with TextPad 8.12.0. Is this the version you are running?

Can anyone else reproduce it?

Posted: Wed Aug 03, 2022 1:12 pm
by AmigoJack
Can confirm with 8.4.2x64 on Win7x64 that "Replace All" will make TextPad unresponsive forever (endless loop?), but not directly crash.

Posted: Wed Aug 03, 2022 2:16 pm
by terrypin
Thanks both. This is TextPad 7.6.4 (64-bit Edition), running in Win 10 Version 20H2 (OS Build 19042.1706)

It not only becomes unresponsive here but also prevents access to any other apps. Task Mgr does eventually open but that too is unresponsive, forcing a Restart. Essentially my definition of a crash!

Posted: Wed Aug 03, 2022 5:41 pm
by MudGuard
Let's say we start the replacement at position 0.
\)? matches "nothing", i.e. a String of length 0 (which extends from position 0 to position 0).
This string is then replaced by nothing (which starts/ends at position 0).
The start position for the next search is then placed behind the replacement, i.e. at position 0.

Then \)? matches "nothing", i.e. a String of length 0 (which extends from position 0 to position 0).
This string is then replaced by nothing (which starts/ends at position 0).
The start position for the next search is then placed behind the replacement, i.e. at position 0.

Then \)? matches "nothing", i.e. a String of length 0 (which extends from position 0 to position 0).
This string is then replaced by nothing (which starts/ends at position 0).
The start position for the next search is then placed behind the replacement, i.e. at position 0.

Then ...

it might take a while :D to get to another position ...

Posted: Wed Aug 03, 2022 5:55 pm
by ben_josephs
The current version of TextPad protects against this endless loop in Replace All by advancing the cursor after matching an empty string. Older versions didn't.

There are two morals here:
1. avoid regexes that match empty strings;
2. use the current version of TextPad.

Posted: Thu Aug 04, 2022 8:17 am
by terrypin
Thanks both.

Appreciate that detailed explanation, MudGuard, but confess I don't understand 'position 0'? At the start of a line, surely the text cursor is always at position 1?

Posted: Thu Aug 04, 2022 8:30 am
by ben_josephs
MudGuard counts from 0, as do most programmers and mathematicians (although, when not programming, from long-standing habit, even they usually count lines and character positions from 1).

Posted: Thu Aug 04, 2022 4:08 pm
by AmigoJack
ben_josephs wrote:as do most programmers and mathematicians
That's why cups of them say "World's #0 programmer". ;)

Image