]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/maps.c
Fix bitmap overruns when WORLD_X * WORLD_Y not a multiple of 16
[empserver] / src / lib / subs / maps.c
index c8b62051d9de5726f82677d6d229c9601ae369c9..14e894642868af34d01819d904a46055634e09e4 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  maps.c: Map routines
- * 
+ *
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1998
+ *     Markus Armbruster, 2004-2011
  *     Ron Koenderink, 2006
  */
 
@@ -147,7 +148,7 @@ draw_map(int bmap, char origin, int map_flags, struct nstr_sect *nsp)
        }
     }
     if (!bitmap)
-       bitmap = malloc(WORLD_SZ() / 8);
+       bitmap = malloc((WORLD_SZ() + 7) / 8);
     if (!wmapbuf || !wmap || !bitmap) {
        pr("Memory error, tell the deity.\n");
        logerror("malloc failed in draw_map\n");
@@ -174,7 +175,6 @@ draw_map(int bmap, char origin, int map_flags, struct nstr_sect *nsp)
        switch (bmap) {
        default:
            CANT_REACH();
-           bmap = 'b';
            /* fall through */
        case 'b':
            while (bmnxtsct(nsp) && !player->aborted) {
@@ -202,7 +202,7 @@ draw_map(int bmap, char origin, int map_flags, struct nstr_sect *nsp)
                struct sctstr sect;
 
                if (!player->god) {
-                   memset(bitmap, 0, WORLD_SZ() / 8);
+                   memset(bitmap, 0, (WORLD_SZ() + 7) / 8);
                    bitinit2(nsp, bitmap, player->cnum);
                }
                while (nxtsct(nsp, &sect) && !player->aborted) {
@@ -221,7 +221,7 @@ draw_map(int bmap, char origin, int map_flags, struct nstr_sect *nsp)
        int changed = 0;
 
        if (!player->god) {
-           memset(bitmap, 0, WORLD_SZ() / 8);
+           memset(bitmap, 0, (WORLD_SZ() + 7) / 8);
            bitinit2(nsp, bitmap, player->cnum);
        }
        while (nxtsct(nsp, &sect) && !player->aborted) {
@@ -264,13 +264,7 @@ draw_map(int bmap, char origin, int map_flags, struct nstr_sect *nsp)
        struct sctstr sect;
 
        snxtsct_rewind(nsp);
-       if (!player->god) {
-           memset(bitmap, 0, WORLD_SZ() / 8);
-           bitinit2(nsp, bitmap, player->cnum);
-       }
        while (nxtsct(nsp, &sect) && !player->aborted) {
-           if (!player->god && !emp_getbit(nsp->x, nsp->y, bitmap))
-               continue;
            if (sect.sct_own == player->cnum)
                 wmap[nsp->dy][nsp->dx] |= 0x80;
        }
@@ -426,6 +420,9 @@ share_bmap(natid from, natid to, struct nstr_sect *ns, char des,
     char todes;
     char from_des = *from_name;
 
+    if (from == to)
+       return 0;
+
     if (isalpha(from_des))
        from_des &= ~0x20;