]> granicus.if.org Git - nethack/commitdiff
Silence valgrind uninitialized bytes complaints
authorPasi Kallinen <paxed@alt.org>
Sat, 7 Jan 2023 11:20:39 +0000 (13:20 +0200)
committerPasi Kallinen <paxed@alt.org>
Sat, 7 Jan 2023 11:25:07 +0000 (13:25 +0200)
Just zero out the allocated memory.

Explicitly setting struct field values isn't enough, because field alignment
means there can be several unused bytes which are written to savefile.

src/dungeon.c
src/mklev.c

index 1f0c56519571b8b18176b6a8c4745095c3ee4e23..07cd2f56bea379fc726419538a04b96238ae7e2a 100644 (file)
@@ -1484,6 +1484,7 @@ stairway_add(coordxy x, coordxy y, boolean up, boolean isladder, d_level *dest)
 {
     stairway *tmp = (stairway *) alloc(sizeof (stairway));
 
+    (void) memset((genericptr_t) tmp, 0, sizeof (stairway));
     tmp->sx = x;
     tmp->sy = y;
     tmp->up = up;
index 388591db781f26c3ec24dd899756ef30f0a89734..3de0635e45520f9565b34ab623e923ccc4c4c435 100644 (file)
@@ -458,6 +458,8 @@ alloc_doors(void)
     if (!gd.doors || gd.doorindex >= gd.doors_alloc) {
         int c = gd.doors_alloc + DOORINC;
         coord *doortmp = (coord *) alloc(c * sizeof(coord));
+
+        (void) memset((genericptr_t) doortmp, 0, c * sizeof(coord));
         if (gd.doors) {
             (void) memcpy(doortmp, gd.doors, gd.doors_alloc * sizeof(coord));
             free(gd.doors);