]> granicus.if.org Git - nethack/commitdiff
potentially uninitialized variable warnings
authornhmall <nhmall@nethack.org>
Sun, 9 Oct 2022 13:11:56 +0000 (09:11 -0400)
committernhmall <nhmall@nethack.org>
Sun, 9 Oct 2022 13:11:56 +0000 (09:11 -0400)
src/mkroom.c(1068) :
warning C4701: potentially uninitialized local variable 'insidex' used
src/mkroom.c(1070) :
warning C4701: potentially uninitialized local variable 'insidey' used

The warning is because the insidex and insidey variables only get
assigned a value conditionally within a for-loop, but contain random
values if that for-loop is not executed, and they are used unconditionaly
later on in the code.

Initializing them changes that from containing random values to containing
zeros, whether that is appropriate or not.

In this particular case, insidex and insidey look to be riding on the coat
tails of insidect and there is a check for invalid insidect in the code,
so that should catch the situation.

src/mkroom.c

index 5389e02d07f412a306066c4beaf504d32b84e68a..a02d816d038e4429d1907a83a6313641a1df215e 100644 (file)
@@ -1041,7 +1041,7 @@ invalid_shop_shape(struct mkroom *sroom)
     coordxy x, y;
     coordxy doorx = g.doors[sroom->fdoor].x;
     coordxy doory = g.doors[sroom->fdoor].y;
-    coordxy insidex, insidey, insidect = 0;
+    coordxy insidex = 0, insidey = 0, insidect = 0;
 
     /* First, identify squares inside the room and next to the door. */
     for (x = max(doorx - 1, sroom->lx);