]> git.pond.sub.org Git - empserver/commitdiff
fire launch: Avoid "may be used uninitialized" warnings
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 23 Jan 2021 07:48:56 +0000 (08:48 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 6 Feb 2021 15:55:37 +0000 (16:55 +0100)
launch_missile() initializes @n to the target ship number only when
the target is a ship.  It also uses it only then, to re-get the ship.
Clang is cool with this, but GCC gets confused and warns "ā€˜nā€™ may be
used uninitialized".

Use target_ship.shp_uid instead of @n to avoid the warning.

Similar issue in c_fire(): use vship.shp_uid instead of for @vhsipno.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/commands/laun.c
src/lib/commands/mfir.c

index 9e1466b5cb282d0f0d7db4de2d68e115f4af1b8d..15ba87a21461a0b349ba82ae46b72169469ecaaa 100644 (file)
@@ -263,7 +263,8 @@ launch_missile(struct plnstr *pp)
                       target_ship.shp_x, target_ship.shp_y,
                       target_ship.shp_own, &sublaunch) < 0)
            return RET_OK;
-       getship(n, &target_ship);
+       /* @target_ship may have expended shells defending */
+       getship(target_ship.shp_uid, &target_ship);
        if (!msl_hit(pp, shp_hardtarget(&target_ship), EF_SHIP,
                     N_SHP_MISS, N_SHP_SMISS, sublaunch,
                     target_ship.shp_own)) {
index cb1eb9c5899410d358768ebe911f4df8b42fff65..de2aa0a45e45ecfd0fbdef4062d597f5ed4d8c6f 100644 (file)
@@ -393,7 +393,7 @@ c_fire(void)
            putsect(&vsect);
            break;
        default:
-           getship(vshipno, &vship);
+           getship(vship.shp_uid, &vship);
            shipdamage(&vship, dam);
            if (vship.shp_effic < SHIP_MINEFF)
                pr("%s sunk!\n", prsub(&vship));