Skip to content

Fix: crash using cut#7063

Merged
vadi2 merged 1 commit intoMudlet:developmentfrom
SlySven:Fix_crash_using_cut
Jan 1, 2024
Merged

Fix: crash using cut#7063
vadi2 merged 1 commit intoMudlet:developmentfrom
SlySven:Fix_crash_using_cut

Conversation

@SlySven
Copy link
Copy Markdown
Member

@SlySven SlySven commented Dec 31, 2023

Actually it was being cause by a failure to reset (QPoint) TConsole::P_begin and (QPoint) TConsole::P_end - which are used to record the selection in the event that the TBuffer was empty or for some other reason the selection was not found when called from selectString(...) which uses (int) TConsole::select(const QString, int).

There was also a Hindenbug lying in TConsole::insertLink(...) and TConsole::insertText(...) where if buffer.buffer.empty() was true, execution would then proceed to evaluate buffer.buffer[0].empty() which is undefined behaviour because there would not be a buffer.buffer[0]!

This should close #4634 - which I have reproduced in the current development branch code with the following function:

function testCut()

clearWindow()
feedTriggers("This is a test line.\n")
selectString(line, 1)
cut()

tempTimer(3, "feedTriggers(\"This is a second test line.\n\")")

tempTimer(6, "selectString(line, 1) cut()")

end

After the first time this is called, repeats will crash Mudlet when the 6 second delayed selectString(line, 1) cut() is called. One thing to note is that this code actually fails to follow the Wiki guidance for selectString(...) which says "Note: To prevent working on random text if your selection didn't actually select anything, check the -1 return code before doing changes"!

/claim #4634

Actually it was being cause by a failure to reset
`(QPoint) TConsole::P_begin` and `(QPoint) TConsole::P_end` - which are
used to record the selection in the event that the `TBuffer` was empty or
for some other reason the selection was not found when called from
`selectString(...)` which uses `(int) TConsole::select(const QString, int)`.

There was also a Hindenbug lying in `TConsole::insertLink(...)` and
`TConsole::insertText(...)` where if `buffer.buffer.empty()` was `true`,
execution would then proceed to evaluate `buffer.buffer[0].empty()` which
is undefined behaviour because there would not **be** a `buffer.buffer[0]`!

This should close Mudlet#4634 - which I have reproduced in the current
`development` branch code with the following function:
```lua
function testCut()

clearWindow()
feedTriggers("This is a test line.\n")
selectString(line, 1)
cut()

tempTimer(3, "feedTriggers(\"This is a second test line.\n\")")

tempTimer(6, "selectString(line, 1) cut()")

end
```

After the first time this is called, repeats will crash Mudlet when the 6
second delayed `selectString(line, 1) cut()` is called. One thing to note
is that this code actually fails to follow the Wiki guidance for
**[`selectString(...)`](https://wiki.mudlet.org/w/Manual:Lua_Functions#selectString)**
which says "Note: To prevent working on random text if your selection
didn't actually select anything, check the -1 return code before doing
changes"!

/claim Mudlet#4634

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
@SlySven SlySven requested a review from a team as a code owner December 31, 2023 22:07
@SlySven SlySven requested a review from a team December 31, 2023 22:07
@algora-pbc algora-pbc bot mentioned this pull request Dec 31, 2023
@algora-pbc
Copy link
Copy Markdown

algora-pbc bot commented Dec 31, 2023

💵 To receive payouts, sign up on Algora, link your Github account and connect with Stripe/Alipay.

@add-deployment-links
Copy link
Copy Markdown

add-deployment-links bot commented Dec 31, 2023

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.

@vadi2 vadi2 merged commit bd8597b into Mudlet:development Jan 1, 2024
vadi2 pushed a commit to vadi2/Mudlet that referenced this pull request Jan 5, 2024
Actually it was being cause by a failure to reset `(QPoint)
TConsole::P_begin` and `(QPoint) TConsole::P_end` - which are used to
record the selection in the event that the `TBuffer` was empty or for
some other reason the selection was not found when called from
`selectString(...)` which uses `(int) TConsole::select(const QString,
int)`.

There was also a Hindenbug lying in `TConsole::insertLink(...)` and
`TConsole::insertText(...)` where if `buffer.buffer.empty()` was `true`,
execution would then proceed to evaluate `buffer.buffer[0].empty()`
which is undefined behaviour because there would not **be** a
`buffer.buffer[0]`!

This should close Mudlet#4634 - which I have reproduced in the current
`development` branch code with the following function:
```lua
function testCut()

clearWindow()
feedTriggers("This is a test line.\n")
selectString(line, 1)
cut()

tempTimer(3, "feedTriggers(\"This is a second test line.\n\")")

tempTimer(6, "selectString(line, 1) cut()")

end
```

After the first time this is called, repeats will crash Mudlet when the
6 second delayed `selectString(line, 1) cut()` is called. One thing to
note is that this code actually fails to follow the Wiki guidance for
**[`selectString(...)`](https://wiki.mudlet.org/w/Manual:Lua_Functions#selectString)**
which says "Note: To prevent working on random text if your selection
didn't actually select anything, check the -1 return code before doing
changes"!

/claim Mudlet#4634

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crash using cut()

2 participants