From: Markus Armbruster Date: Sat, 23 Jan 2021 09:06:49 +0000 (+0100) Subject: subs/wu: Avoid "may be used uninitialized" warnings X-Git-Tag: v4.4.1~12 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=e23882161e21b6e14dc9283933967d344f231954 subs/wu: Avoid "may be used uninitialized" warnings 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 --- 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