fix-unit-occupancy: Handle invalid coordinates instead of crashing

It appears that positions of caged units brought by traders can be
invalid, in particular.
develop
lethosor 2015-11-25 22:32:54 -05:00
parent 597ed1510e
commit 428a0a4cfe
2 changed files with 8 additions and 3 deletions

@ -36,7 +36,7 @@ Fixes
----- -----
- Fixed a rare crash that could result from running `keybinding` in onLoadWorld.init - Fixed a rare crash that could result from running `keybinding` in onLoadWorld.init
- Script help that doesn't start with a space is now recognized correctly - Script help that doesn't start with a space is now recognized correctly
- `confirm`: Fixed issues with haul-delete, route-delete, and squad-disband confirmations intercepting keys too agressively - `confirm`: Fixed issues with haul-delete, route-delete, and squad-disband confirmations intercepting keys too aggressively
- `fix-unit-occupancy`: Significantly optimized - up to 2,000 times faster in large fortresses - `fix-unit-occupancy`: Significantly optimized - up to 2,000 times faster in large fortresses
- `gui/create-item`: Allow exiting quantity prompt - `gui/create-item`: Allow exiting quantity prompt
- `modtools/create-unit`: Fixed a possible issue in reclaim fortress mode - `modtools/create-unit`: Fixed a possible issue in reclaim fortress mode

@ -80,11 +80,16 @@ struct uo_buf {
} }
inline uint8_t get (uint32_t x, uint32_t y, uint32_t z) inline uint8_t get (uint32_t x, uint32_t y, uint32_t z)
{ {
return buf[offset(x, y, z)]; size_t off = offset(x, y, z);
if (off < size)
return buf[off];
return 0;
} }
inline void set (uint32_t x, uint32_t y, uint32_t z, uint8_t val) inline void set (uint32_t x, uint32_t y, uint32_t z, uint8_t val)
{ {
buf[offset(x, y, z)] = val; size_t off = offset(x, y, z);
if (off < size)
buf[off] = val;
} }
inline void get_coords (size_t off, uint32_t &x, uint32_t &y, uint32_t &z) inline void get_coords (size_t off, uint32_t &x, uint32_t &y, uint32_t &z)
{ {