]> git.pond.sub.org Git - empserver/commitdiff
subs/wu: Avoid "may be used uninitialized" warnings
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 23 Jan 2021 09:06:49 +0000 (10:06 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 6 Feb 2021 15:55:37 +0000 (16:55 +0100)
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 <armbru@pond.sub.org>
src/lib/subs/wu.c

index 355685ece9dd7f4f1d7554ac98bf1bde5705aa8f..6bcaf0009bffe8d415ad86c5e61fa88a34c5c43e 100644 (file)
@@ -28,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Steve McClure, 2000
- *     Markus Armbruster, 2005-2016
+ *     Markus Armbruster, 2005-2021
  */
 
 #include <config.h>
@@ -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