Replace broken GCFx(), GCFy() by sctoff()
GCFx() and GCFy() pointlessly duplicate sctoff(), and don't work when the argument is less than -WORLD_X or -WORLD_Y, respectively. With current code, this happens only for impractically tiny worlds: emp_setbitmap() writes to bitmap[] out of bounds, and smashes the heap.
This commit is contained in:
parent
6316c4185a
commit
c89f8172ec
1 changed files with 10 additions and 13 deletions
|
@ -114,25 +114,22 @@ static int *bitmaps[5] = {
|
||||||
bitmap4,
|
bitmap4,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define GCFx(x) ((x + WORLD_X) % WORLD_X)
|
|
||||||
#define GCFy(y) ((y + WORLD_Y) % WORLD_Y)
|
|
||||||
|
|
||||||
int
|
int
|
||||||
emp_getbit(int x, int y, unsigned char *bitmap)
|
emp_getbit(int x, int y, unsigned char *bitmap)
|
||||||
{
|
{
|
||||||
int id;
|
int id = sctoff(x, y);
|
||||||
|
if (id < 0)
|
||||||
id = (GCFy(y)) * WORLD_X / 2 + GCFx(x) / 2;
|
return 0;
|
||||||
return bitmap[id / 8] & bit(id & 07);
|
return bitmap[id >> 3] & bit(id & 07);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
emp_setbit(int x, int y, unsigned char *bitmap)
|
emp_setbit(int x, int y, unsigned char *bitmap)
|
||||||
{
|
{
|
||||||
int id;
|
int id = sctoff(x, y);
|
||||||
|
if (id < 0)
|
||||||
id = (GCFy(y)) * WORLD_X / 2 + GCFx(x) / 2;
|
return;
|
||||||
bitmap[id / 8] |= bit(id & 07);
|
bitmap[id >> 3] |= bit(id & 07);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -145,8 +142,8 @@ emp_setbitmap(int x, int y, unsigned char *bitmap, int *bitmaps)
|
||||||
for (mp = bitmaps; *mp != 9999;) {
|
for (mp = bitmaps; *mp != 9999;) {
|
||||||
dx = x + *mp++;
|
dx = x + *mp++;
|
||||||
dy = y + *mp++;
|
dy = y + *mp++;
|
||||||
id = (GCFy(dy)) * WORLD_X / 2 + GCFx(dx) / 2;
|
id = sctoff(dx, dy);
|
||||||
bitmap[id / 8] |= bit(id & 07);
|
bitmap[id >> 3] |= bit(id & 07);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue