fix three plugin crash/UB bugs; test coverage for 14 plugins - #5939
Alistair-Afton wants to merge 12 commits into
Conversation
f3c1610 to
6e64b3a
Compare
583dfb2 to
14ccd5b
Compare
|
Root cause of the recurring Fixed in f42685d: both tests now save/restore |
SilasD
left a comment
There was a problem hiding this comment.
this is not a full review, I will do that on another day as I am running out of steam today.
in general I don't care about correct code in test suites nearly as much as correct code in tools.
| local was_paused = df.global.pause_state | ||
| return dfhack.with_finalize(function() | ||
| df.global.pause_state = was_paused |
There was a problem hiding this comment.
please use the existing API:
dfhack.world.ReadPauseState()
Returns true if the game is paused.
dfhack.world.SetPauseState(paused)
Sets the pause state of the game.
| item.flags.dump = true | ||
| -- undestroy only restores marks made in the same frame, so the | ||
| -- game must stay paused between destroy and undestroy | ||
| df.global.pause_state = true |
| local was_paused = df.global.pause_state | ||
| return dfhack.with_finalize(function() | ||
| local des = des_at(x, y, z) | ||
| des.flow_size = 0 | ||
| df.global.pause_state = was_paused | ||
| clear_cursor() | ||
| end, function() | ||
| -- pause so the magma cannot spread before we clean it up | ||
| df.global.pause_state = true |
There was a problem hiding this comment.
and existing pause API here.
std::stoi throws uncaught on non-numeric input, crashing the game. Use string_to_int and reject invalid ids with CR_WRONG_USAGE.
parameters[1] was read unconditionally when the first parameter was 'set', which is undefined behavior when fewer arguments are given.
MapExtras::Block::biomeIndexAt returns -1 when the biome lookup fails, and biome_by_idx.at(-1) threw std::out_of_range. The exception escaped the plugin command handler and terminated the game. Return NULL like the existing unresolvable-layer path.
Tests must not leak global state to subsequent tests. Restore the prior pause_state instead of forcing unpaused, and restore suspendmanager's persisted preventblocking value instead of hardcoding it.
934c663 to
610c05d
Compare
Trigger real fey/fell/macabre moods per skill and assert the generated job_items match the documented vanilla sets, that BAR and CLOTH demands carry the dimension-corrected quantities (the plugin's vanilla bugfix), and that thread is never requested.
The fallback race lookup dereferenced civ without a null check, so a site whose owner has an undefined race and whose civ_id does not resolve crashed DF (observed as an access violation in CI on the Windows empty-config leg). Assign the civ's race as the intended fallback and only warn when the owner's race is actually undefined.
|
The Windows empty-config leg failure is root-caused and fixed in a38d479: Fixed by guarding the null civ and actually assigning the intended civ-race fallback. Verified in-game: |
| local function set_cursor(x, y, z) | ||
| df.global.cursor:assign{x=x, y=y, z=z} | ||
| end | ||
|
|
||
| local function clear_cursor() | ||
| df.global.cursor:assign{x=-30000, y=-30000, z=-30000} | ||
| end |
There was a problem hiding this comment.
we have a getter, a setter, and a clearer for these, not in the core API but in a rather obscure place:
local dwarfmode = require('gui.dwarfmode') -- near the top of the script
printall(dwarfmode.getCursorPos()) -- returns nil on invalid cursor.
dwarfmode.setCursorPos( xyz2pos(1,2,3) )
dwarfmode.clearCursorPos()
OTOH this is just a test harness. I won't insist that you use them.
also that's a very old module; much of it became obsolete with the move to 0.50+. all of the Viewport class and all of the DwarfOverlay class are obsolete and have been replaced with the Widgets hierarchy, everything related to the Sidebar is obsolete and definately nonfunctional, I wouldn't trust MOVEMENT_KEYS to still be valid.
dead code everywhere. this needs a weed-whacker. I wonder if any of that stuff is still referenced anywhere else.
the Cursor functions still work, the Selection functions might still work.
update or not, as you choose. I'll do a full review another day; my eyes are blurring.
Summary
3dveins: fix a crash when a tile's biome cannot be resolved (biome_by_idx.at(-1)threwstd::out_of_range, which escaped the command handler and terminated the game)strangemood: fix a crash when--idis given a non-numeric value (std::stoithrew uncaught); invalid ids now return a usage errorsuspendmanager: fix an out-of-bounds parameter read whensetis given too few arguments3dveins,autodump,changeitem,changelayer,createitem,deramp,export-world-map,filltraffic,flows,liquids,showmood,strangemood,suspendmanager, andtubefill(57 tests)Test plan