From: Markus Armbruster Date: Sat, 23 Jan 2021 07:47:22 +0000 (+0100) Subject: load tend: Avoid "may be used uninitialized" warnings X-Git-Tag: v4.4.1~14 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=1f6b79dd10c841d99d8cf5e94528edb45af19592 load tend: Avoid "may be used uninitialized" warnings c_load() initializes @ich only when @type is EF_SECTOR. It also uses it only then. Clang is cool with this, but GCC gets confused and warns "‘ich’ may be used uninitialized". Ron Koenderink reports Visual Studio 2019 even flags it as an error. Same for c_lload() and c_tend(). Time to clean this up. Rearrange the code to avoid the warning and also improve readability a bit. Signed-off-by: Markus Armbruster --- diff --git a/src/lib/commands/load.c b/src/lib/commands/load.c index b3e9b60c1..62847837d 100644 --- a/src/lib/commands/load.c +++ b/src/lib/commands/load.c @@ -30,7 +30,7 @@ * David Sharnoff, 1987 * Ken Stevens, 1995 (rewritten) * Steve McClure, 1998-2000 - * Markus Armbruster, 2004-2018 + * Markus Armbruster, 2004-2021 */ #include @@ -79,12 +79,12 @@ c_load(void) "What commodity (or 'plane' or 'land')? ", buf); if (!p || !*p) return RET_SYN; - + ich = item_by_name(p); if (!strncmp(p, "plane", 5)) type = EF_PLANE; else if (!strncmp(p, "land", 4)) type = EF_LAND; - else if (NULL != (ich = item_by_name(p))) + else if (ich) type = EF_SECTOR; else { pr("Can't %sload '%s'\n", loading ? "" : "un", p); @@ -208,11 +208,12 @@ c_lload(void) "What commodity (or 'plane' or 'land')? ", buf); if (!p || !*p) return RET_SYN; + ich = item_by_name(p); if (!strncmp(p, "plane", 5)) type = EF_PLANE; else if (!strncmp(p, "land", 4)) type = EF_LAND; - else if (NULL != (ich = item_by_name(p))) + else if (ich) type = EF_SECTOR; else { pr("Can't %sload '%s'\n", loading ? "" : "un", p); diff --git a/src/lib/commands/tend.c b/src/lib/commands/tend.c index 5bce71772..3f037714c 100644 --- a/src/lib/commands/tend.c +++ b/src/lib/commands/tend.c @@ -30,7 +30,7 @@ * Dave Pare, 1986 * Thomas Ruschak, 1992 * Steve McClure, 2000 - * Markus Armbruster, 2004-2017 + * Markus Armbruster, 2004-2021 */ #include @@ -70,10 +70,10 @@ c_tend(void) buf); if (!p || !*p) return RET_SYN; - + ip = item_by_name(p); if (!strncmp(p, "land", 4)) type = EF_LAND; - else if (NULL != (ip = item_by_name(p))) + else if (ip) type = EF_SECTOR; else { pr("Can't tend '%s'\n", p);