Fix crash bug in satellite maps

The value of diffx() had the wrong sign when the arguments differed by
WORLD_X / 2.  Same for diffy() and WORLD_Y / 2.  satmap() used them to
find the vector from map center to ship or land unit to put on the
map, and got incorrect values for ships and land units directly
opposite to the center in x or y.  The bug made satmap() read a
pointer out bounds of its malloced radbuf[], and then write through
that with unpredictable consequences.

Broken in 4.2.12.  The original bug was in Empire 1.1: it
miscalculated where to put ships on the map (no crash).  An incomplete
fix for radmap() and satmap() appeared in Chainsaw 2 (still no crash).
radmap() got fixed correctly in Chainsaw 3, but satmap() was
forgotten.  That one got "fixed" in 4.2.7, and again in 4.2.12, but
both "fixes" were flawed and could crash.

Fix by backing out the flawed fixes and adopting the fix from radmap()
instead.
(cherry picked from commit 0cc474bd6d)
This commit is contained in:
Markus Armbruster 2008-05-13 08:36:06 +02:00 committed by Markus Armbruster
parent 7dc0f48868
commit e1283b118a
3 changed files with 4 additions and 48 deletions

View file

@ -41,34 +41,6 @@
#include "optlist.h"
#include "prototypes.h"
int
diffx(int x1, int x2)
{
int dx;
dx = x1 - x2;
dx = dx % WORLD_X;
if (dx > WORLD_X / 2)
dx = dx - WORLD_X;
if (dx < -WORLD_X / 2)
dx = dx + WORLD_X;
return dx;
}
int
diffy(int y1, int y2)
{
int dy;
dy = y1 - y2;
dy = dy % WORLD_Y;
if (dy > WORLD_Y / 2)
dy = dy - WORLD_Y;
if (dy < -WORLD_Y / 2)
dy = dy + WORLD_Y;
return dy;
}
int
deltax(int x1, int x2)
{