]> git.pond.sub.org Git - empserver/commitdiff
bomb launch interdiction: Fix crash on bombs missing target
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 27 Dec 2020 11:43:19 +0000 (12:43 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 17 Jan 2021 20:24:28 +0000 (21:24 +0100)
plane damage() prints @noisy with snprintf() even when it's null.  It
doesn't actually use the output then.  Some systems (GNU, Windows)
deal gracefully with printing null strings, others crash.  @noisy is
null when bombers or missiles miss and do collateral damage.  Affects
bomb, launch, and interdiction missions.  Broken in commit 820d755e5
"subs: Change pln_damage()'s parameter noisy to string prefix",
v4.3.33.

Fix by guarding the snprintf().

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/subs/plnsub.c

index 28653ea6890a4b1720fedf39144295cffe92205a..29c1f9af095599e7c13e31f891e90516bcb80167 100644 (file)
@@ -30,7 +30,7 @@
  *     Dave Pare, 1986
  *     Ken Stevens, 1995
  *     Steve McClure, 1998-2000
  *     Dave Pare, 1986
  *     Ken Stevens, 1995
  *     Steve McClure, 1998-2000
- *     Markus Armbruster, 2004-2016
+ *     Markus Armbruster, 2004-2020
  */
 
 #include <config.h>
  */
 
 #include <config.h>
@@ -1052,7 +1052,7 @@ pln_damage(struct plnstr *pp, char type, char *noisy)
        aim = 100 - aim;
     }
 
        aim = 100 - aim;
     }
 
-    len = snprintf(buf, sizeof(buf), "%s", noisy);
+    len = noisy ? snprintf(buf, sizeof(buf), "%s", noisy) : 0;
     while (i--) {
        if (noisy) {
            if (len > 75) {
     while (i--) {
        if (noisy) {
            if (len > 75) {