]> git.pond.sub.org Git - empserver/commitdiff
Fix size of sector bitmap in do_look() and draw_map()
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 23 Aug 2008 18:41:07 +0000 (14:41 -0400)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 27 Aug 2008 01:42:32 +0000 (21:42 -0400)
They allocated twice as much as needed.

src/lib/commands/look.c
src/lib/subs/maps.c

index 92a635e2b780faa9d590029f1ed4925c4c6b2e16..2ee22047a40b7c0e481114b2cc2010c6e5a5c8de 100644 (file)
@@ -72,12 +72,12 @@ do_look(short type)
 
     if (!snxtitem(&ni, type, player->argp[1], NULL))
        return RET_SYN;
-    if ((bitmap = malloc((WORLD_X * WORLD_Y) / 8)) == 0) {
+    bitmap = calloc(WORLD_SZ() / 8, 1);
+    if (!bitmap) {
        logerror("malloc failed in do_look\n");
        pr("Memory error.  Tell the deity.\n");
        return RET_FAIL;
     }
-    memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
     while (nxtitem(&ni, &unit)) {
        if (!player->owner)
            continue;
index 67b4561e312c9269fec8f0873c3179319bd95bca..c8b62051d9de5726f82677d6d229c9601ae369c9 100644 (file)
@@ -147,7 +147,7 @@ draw_map(int bmap, char origin, int map_flags, struct nstr_sect *nsp)
        }
     }
     if (!bitmap)
-       bitmap = malloc((WORLD_X * WORLD_Y) / 8);
+       bitmap = malloc(WORLD_SZ() / 8);
     if (!wmapbuf || !wmap || !bitmap) {
        pr("Memory error, tell the deity.\n");
        logerror("malloc failed in draw_map\n");
@@ -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_X * WORLD_Y) / 8);
+                   memset(bitmap, 0, WORLD_SZ() / 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_X * WORLD_Y) / 8);
+           memset(bitmap, 0, WORLD_SZ() / 8);
            bitinit2(nsp, bitmap, player->cnum);
        }
        while (nxtsct(nsp, &sect) && !player->aborted) {
@@ -265,7 +265,7 @@ draw_map(int bmap, char origin, int map_flags, struct nstr_sect *nsp)
 
        snxtsct_rewind(nsp);
        if (!player->god) {
-           memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
+           memset(bitmap, 0, WORLD_SZ() / 8);
            bitinit2(nsp, bitmap, player->cnum);
        }
        while (nxtsct(nsp, &sect) && !player->aborted) {