From e23882161e21b6e14dc9283933967d344f231954 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 23 Jan 2021 10:06:49 +0100 Subject: [PATCH] subs/wu: Avoid "may be used uninitialized" warnings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit typed_wu() either sends a telegram to a single recipient @to, or an announcement. It initializes @np to getnatp(to) only when sending a telegram. It also uses it only then. Clang is cool with this, but GCC gets confused and warns "‘np’ may be used uninitialized". Ron Koenderink reports Visual Studio 2019 even flags it as an error. Time to clean this up. Initialize @np to NULL when sending an announcement. Fuse conditionals while there. Signed-off-by: Markus Armbruster --- src/lib/subs/wu.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lib/subs/wu.c b/src/lib/subs/wu.c index 355685ece..6bcaf0009 100644 --- a/src/lib/subs/wu.c +++ b/src/lib/subs/wu.c @@ -28,7 +28,7 @@ * * Known contributors to this file: * Steve McClure, 2000 - * Markus Armbruster, 2005-2016 + * Markus Armbruster, 2005-2021 */ #include @@ -110,14 +110,16 @@ typed_wu(natid from, natid to, char *message, int type) char box[1024]; struct player *other; - if (type == TEL_ANNOUNCE) + if (type == TEL_ANNOUNCE) { strcpy(box, annfil); - else + np = NULL; + } else { mailbox(box, to); - - if (type != TEL_ANNOUNCE) - if (!(np = getnatp(to)) || np->nat_stat < STAT_SANCT) + np = getnatp(to); + if (!np || np->nat_stat < STAT_SANCT) return -1; + } + #if !defined(_WIN32) if ((fd = open(box, O_WRONLY | O_APPEND, 0)) < 0) { #else -- 2.43.0