]> git.pond.sub.org Git - empserver/commitdiff
(XYOFFSET): Returned twice the value it should.
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 28 Jul 2007 07:06:55 +0000 (07:06 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 28 Jul 2007 07:06:55 +0000 (07:06 +0000)
(finish_sects): Allocated twice as much space as needed, to make it
work with the broken XYOFFSET().

include/xy.h
src/lib/update/finish.c

index 60c2c886031b238d617c218f0cbb8c8d08de1240..5df03c79667e6210a614e84837602a72068ba516 100644 (file)
@@ -36,9 +36,8 @@
 
 #include "types.h"
 
-/* Used to calculate an offset into an array.  Used for
-   dynamically sizing the world. */
-#define XYOFFSET(x, y) (((y) * WORLD_X) + (x))
+/* Fast version of sctoff() for normalized arguments: */
+#define XYOFFSET(x, y) (((y) * WORLD_X + (x)) / 2)
 
 #define XNORM(x) \
     (((x) < 0) ? ((WORLD_X - (-(x) % WORLD_X)) % WORLD_X) : ((x) % WORLD_X))
index 5c2eb40c20296f34cb88a4fbfc86827ffad83154..a8464803555e923eba0ff37cec640bd60e585087 100644 (file)
@@ -77,20 +77,15 @@ finish_sects(int etu)
     if (g_distptrs == NULL) {
        logerror("First update since reboot, allocating buffer\n");
        /* Allocate the information buffer */
-       g_distptrs = (struct distinfo *)(malloc((WORLD_X * WORLD_Y) *
-                                               sizeof(struct distinfo)));
+       g_distptrs = malloc((WORLD_X * WORLD_Y / 2) * sizeof(*g_distptrs));
        if (g_distptrs == NULL) {
            logerror("malloc failed in finish_sects.\n");
            return;
        }
-
-       logerror("Allocated '%lu' bytes '%d' indices\n",
-                (unsigned long)(WORLD_X * WORLD_Y * sizeof(struct distinfo)),
-                WORLD_X * WORLD_Y);
     }
 
     /* Wipe it clean */
-    memset(g_distptrs, 0, ((WORLD_X * WORLD_Y) * sizeof(struct distinfo)));
+    memset(g_distptrs, 0, (WORLD_X * WORLD_Y / 2) * sizeof(*g_distptrs));
 
     logerror("delivering...\n");
     /* Do deliveries */