Why does this crash TextPad?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
terrypin
Posts: 172
Joined: Wed Jul 11, 2007 7:50 am

Why does this crash TextPad?

Post 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?
User avatar
bbadmin
Site Admin
Posts: 878
Joined: Mon Feb 17, 2003 8:54 pm
Contact:

Post 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?
User avatar
AmigoJack
Posts: 532
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

Can confirm with 8.4.2x64 on Win7x64 that "Replace All" will make TextPad unresponsive forever (endless loop?), but not directly crash.
terrypin
Posts: 172
Joined: Wed Jul 11, 2007 7:50 am

Post 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!
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Post 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 ...
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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.
terrypin
Posts: 172
Joined: Wed Jul 11, 2007 7:50 am

Post 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?
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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).
User avatar
AmigoJack
Posts: 532
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Post by AmigoJack »

ben_josephs wrote:as do most programmers and mathematicians
That's why cups of them say "World's #0 programmer". ;)

Image
Post Reply