HUD/mcl_death_messages: Fix crash when skeleton kills player using bow #202

Merged
cora merged 2 commits from fix-skelly-crash-2 into master 2021-12-06 19:42:21 +01:00
Owner
Problem

TRACKING ISSUE: #196

Commit 5252952555 used string.gsub() to
strip newlines from tools in death messages. The second return value of
string.gsub() (the number of substitutions) was erroneously returned too
by get_tool_name(). This bug caused a crash whenever a skeleton killed a
player using its bow.

Solution

This patchset uses cora's solution from #197 – only return the first value of string.gsub().

Details

This PR is basically #197 plus a few test cases. It is intended to replace #197 fully.

I have added six assertions to mods/HUD/mcl_death_messages/init.lua to make sure that all code paths through get_tool_name() behave as expected both now and in the future (after a possible refactoring or when the devs break the engine).

Testing Steps
Verify bug

This is not necessary to do as part of a review, it has been done as part of verifying #196 already.

  1. Enter a Minetest world in Mineclonia commit d70c05e92c.
  2. Spawn a skeleton (mobs_mc:skeleton)
  3. Get on a tower at least three nodes high next to the skeleton.
  4. Sneak to the edge.
  5. Get shot by the skeleton. Verify that the server crashes when the player dies.
Verify patch
  1. Enter a Minetest world in Mineclonia commit 609105e091.
  2. Spawn a skeleton (mobs_mc:skeleton)
  3. Get on a tower at least three nodes high next to the skeleton.
  4. Sneak to the edge.
  5. Get shot by the skeleton. Verify that the server does not crash when the player dies.
##### Problem TRACKING ISSUE: https://git.minetest.land/Mineclonia/Mineclonia/issues/196 Commit 5252952555d204e4b5c1a2a4367b36665c476451 used string.gsub() to strip newlines from tools in death messages. The second return value of string.gsub() (the number of substitutions) was erroneously returned too by get_tool_name(). This bug caused a crash whenever a skeleton killed a player using its bow. ##### Solution This patchset uses cora's solution from https://git.minetest.land/Mineclonia/Mineclonia/pulls/197 – only return the first value of string.gsub(). ##### Details This PR is basically https://git.minetest.land/Mineclonia/Mineclonia/pulls/197 plus a few test cases. It is intended to replace https://git.minetest.land/Mineclonia/Mineclonia/pulls/197 fully. I have added six assertions to `mods/HUD/mcl_death_messages/init.lua` to make sure that all code paths through get_tool_name() behave as expected both now and in the future (after a possible refactoring or when the devs break the engine). ##### Testing Steps ###### Verify bug This is not necessary to do as part of a review, it has been done as part of verifying https://git.minetest.land/Mineclonia/Mineclonia/issues/196 already. 1. Enter a Minetest world in Mineclonia commit d70c05e92cd33d86f4984f961f1eba5cd428d5cc. 2. Spawn a skeleton (mobs_mc:skeleton) 3. Get on a tower at least three nodes high next to the skeleton. 4. Sneak to the edge. 5. Get shot by the skeleton. Verify that the server crashes when the player dies. ###### Verify patch 1. Enter a Minetest world in Mineclonia commit 609105e091b0853b68e24770674993dc18acc111. 2. Spawn a skeleton (mobs_mc:skeleton) 3. Get on a tower at least three nodes high next to the skeleton. 4. Sneak to the edge. 5. Get shot by the skeleton. Verify that the server does not crash when the player dies.
erlehmann added 1 commit 2021-12-06 04:06:04 +01:00
f9e3c4fd6d
Fix crash when skeleton kills player using bow
Commit 5252952555 used string.gsub() to
strip newlines from tools in death messages. The second return value of
string.gsub() (the number of substitutions) was erroneously returned too
by get_tool_name(). This bug caused a crash whenever a skeleton killed a
player using its bow.
erlehmann force-pushed fix-skelly-crash-2 from 11630091eb to 609105e091 2021-12-06 04:12:15 +01:00 Compare
cora approved these changes 2021-12-06 19:41:45 +01:00
cora left a comment
Member
Verify patch
  • 1. Enter a Minetest world in Mineclonia commit 609105e091.
  • 2. Spawn a skeleton (mobs_mc:skeleton)
  • 3. Get on a tower at least three nodes high next to the skeleton.
  • 4. Sneak to the edge.
  • 5. Get shot by the skeleton. Verify that the server does not crash when the player dies.
###### Verify patch - [x] 1. Enter a Minetest world in Mineclonia commit 609105e091b0853b68e24770674993dc18acc111. - [x] 2. Spawn a skeleton (mobs_mc:skeleton) - [x] 3. Get on a tower at least three nodes high next to the skeleton. - [x] 4. Sneak to the edge. - [x] 5. Get shot by the skeleton. Verify that the server does not crash when the player dies.
cora merged commit 10670d5c10 into master 2021-12-06 19:42:21 +01:00
cora deleted branch fix-skelly-crash-2 2021-12-06 19:42:23 +01:00
This repo is archived. You cannot comment on pull requests.
No description provided.