chiark / gitweb /
rect: Fix compiler errors about uninitialized use of variables
authorKhem Raj <raj.khem@gmail.com>
Wed, 30 Dec 2015 23:53:36 +0000 (23:53 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 31 Dec 2015 08:28:14 +0000 (08:28 +0000)
error: 'r2.x' may be used uninitialized in this function

Its happening when using gcc 5.3 with musl C library. its considering
the case when case falls into default and immediately after exiting
this there is a check if (r1.h > 0 && r1.w > 0) where r1 element is
used but not assigned anything.

GCC is not noticing the control flow where the initilization will
always work due to assertion call can be a function call from libc

Signed-off-by: Khem Raj <raj.khem@gmail.com>
rect.c

diff --git a/rect.c b/rect.c
index 55667c02a8372dd05ba30992c2643e0e247168f3..fa3a7869703e7cd7a94974ecb035a114313860cd 100644 (file)
--- a/rect.c
+++ b/rect.c
@@ -1317,7 +1317,8 @@ static char *new_game_desc(const game_params *params_in, random_state *rs,
                     if (ndirs > 0) {
                         int which, dir;
                         struct rect r1, r2;
-
+                        memset(&r1, 0, sizeof(struct rect));
+                        memset(&r2, 0, sizeof(struct rect));
                         which = random_upto(rs, ndirs);
                         dir = dirs[which];