Fix bitmap overruns when WORLD_X * WORLD_Y not a multiple of 16
World-sized bitmaps were allocated with size WORLD_SZ() / 8, which expands to (WORLD_X * WORLD_Y / 2) / 8. The divisions truncate unless WORLD_X * WORLD_Y is a multiple of 16. The bitmaps were one byte too small then. Bitmap overruns happen when: * A lookout looks at one of the last sectors of the sector file. Besides commands look and llook, this affects navigate and march sub-command 'l'. * Command spy spies into one of the last sectors of the sector file. * A map or nmap (but not a bmap) shows one of the last sectors of the sector file, or a sector that can see one of the last sectors (visual range is two sectors at 100% efficiency). Besides commands lmap, map, nmap, pmap, smap, this affects move and transport sub-command 'm'. Diagnosed with valgrind. Already broken in BSD Empire 1.1 (bitmaps were on the stack then).
This commit is contained in:
parent
6c9363cc4f
commit
88983a1a2e
3 changed files with 7 additions and 7 deletions
|
@ -30,7 +30,7 @@
|
|||
* Known contributors to this file:
|
||||
* Dave Pare, 1986
|
||||
* Steve McClure, 1998-2000
|
||||
* Markus Armbruster, 2005-2008
|
||||
* Markus Armbruster, 2005-2011
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -86,7 +86,7 @@ spy(void)
|
|||
pr("You don't have the BTU's for spying on that scale!\n");
|
||||
return RET_FAIL;
|
||||
}
|
||||
bitmap = calloc(WORLD_SZ() / 8, 1);
|
||||
bitmap = calloc((WORLD_SZ() + 7) / 8, 1);
|
||||
if (!bitmap) {
|
||||
logerror("malloc failed in do_look\n");
|
||||
pr("Memory error. Tell the deity.\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue