]> git.pond.sub.org Git - empserver/commitdiff
Don't write garbage to unused trade destination in trade file
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 27 Jun 2010 09:35:08 +0000 (11:35 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 25 Jul 2010 15:48:53 +0000 (17:48 +0200)
struct trdstr members trd_x, trd_y are used only for teleporting
trades.  For others, trad() wrote garbage coordinates to the trade
file.  They weren't used except by xdump.  Fortunately, even there
they're visible only to deities.

Write invalid coordinates instead.  Do that in set() as well, so that
coordinates are valid only when we have a teleport destination.

Spotted by the Clang Static Analyzer.

include/trade.h
src/lib/commands/set.c
src/lib/commands/trad.c

index ffd86b4f0f2c750d8c19b6359a1b78bb6a8515a4..b7ed5e37f4c27b12569a1b5b7aa7cda782e9c0c6 100644 (file)
@@ -54,7 +54,7 @@ struct trdstr {
     long trd_price;
     int trd_maxbidder;
     time_t trd_markettime;
-    coord trd_x;
+    coord trd_x;               /* destination for teleporting trade */
     coord trd_y;
 };
 
index a557cf443d1d0322b0b7a5add7c996592ecaa7bf..0f08806604da6ded8bc272c7db0823141b03c60b 100644 (file)
@@ -124,8 +124,8 @@ set(void)
            else
                id = ni_trade.cur;
            ef_blank(EF_TRADE, id, &trade);
-           trade.trd_x = item.gen.x;
-           trade.trd_y = item.gen.y;
+           trade.trd_x = 1;
+           trade.trd_y = 0;
            trade.trd_type = type;
            trade.trd_owner = player->cnum;
            trade.trd_unitid = ni.cur;
index 64d0aed8b1f280d034f6b7f89f061bc9edecec56..6d22dab8f97e1e6d274d3cbc7fa7b42f72dee90d 100644 (file)
@@ -177,11 +177,8 @@ trad(void)
        }
     }
     canspend = natp->nat_money - tally;
-    /*
-     * Find the destination sector for the plane before the trade is
-     * actually made, except for satellites in orbit.  Must be owned
-     * and must be a 60% airfield (except for VTOL planes).
-     */
+
+    /* Find the destination sector for the trade */
     if (((trade.trd_type == EF_PLANE) && !pln_is_in_orbit(&tg.plane))
        || (trade.trd_type == EF_NUKE)) {
        while (1) {
@@ -211,8 +208,7 @@ trad(void)
            }
            break;
        }
-    }
-    if (trade.trd_type == EF_LAND) {
+    } else if (trade.trd_type == EF_LAND) {
        while (1) {
            p = getstring("Destination sector: ", buf);
            if (!trade_check_ok(&trade, &tg))
@@ -238,6 +234,10 @@ trad(void)
            }
            break;
        }
+    } else {
+       /* This trade doesn't teleport; make destination invalid */
+       sx = 1;
+       sy = 0;
     }
 
     p = getstring("How much do you bid: ", buf);