[PATCH] tools: Avoid used-uninitialized warning with some compilers

2 views
Skip to first unread message

Jan Kiszka

unread,
Sep 24, 2026, 5:19:01 AM (7 days ago) Sep 24
to EFI Boot Guard
From: Jan Kiszka <jan.k...@siemens.com>

Seen for armhf with forky toolchain:

In function 'dump_uservars',
inlined from 'dump_env' at tools/bg_printenv.c:208:3:
tools/bg_printenv.c:127:25: error: 'val_snum' may be used uninitialized [-Werror=maybe-uninitialized]
127 | fprintf(stdout, raw ? "=%lld\n" : " = %lld\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
128 | (long long signed int)val_snum);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/bg_printenv.c: In function 'dump_env':
tools/bg_printenv.c:84:17: note: 'val_snum' was declared here
84 | int64_t val_snum;
| ^~~~~~~~
In function 'dump_uservars',
inlined from 'dump_env' at tools/bg_printenv.c:208:3:
tools/bg_printenv.c:109:25: error: 'val_unum' may be used uninitialized [-Werror=maybe-uninitialized]
109 | fprintf(stdout, raw ? "=%llu\n" : " = %llu\n",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
110 | (long long unsigned int)val_unum);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/bg_printenv.c: In function 'dump_env':
tools/bg_printenv.c:83:18: note: 'val_unum' was declared here
83 | uint64_t val_unum;
| ^~~~~~~~

These are false positives because all possibly type values that are fed
into the switch-cases are handled. But that is not obvious on first
sight, also for humans. So let's help both the compiler and the humans
here.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
tools/bg_printenv.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/bg_printenv.c b/tools/bg_printenv.c
index e8c095f..400381b 100644
--- a/tools/bg_printenv.c
+++ b/tools/bg_printenv.c
@@ -102,7 +102,7 @@ static void dump_uservars(uint8_t *udata, bool raw)
case USERVAR_TYPE_UINT32:
val_unum = *((uint32_t *) value);
break;
- case USERVAR_TYPE_UINT64:
+ default: /* USERVAR_TYPE_UINT64 */
val_unum = *((uint64_t *) value);
break;
}
@@ -120,7 +120,7 @@ static void dump_uservars(uint8_t *udata, bool raw)
case USERVAR_TYPE_SINT32:
val_snum = *((int32_t *) value);
break;
- case USERVAR_TYPE_SINT64:
+ default: /* USERVAR_TYPE_SINT64: */
val_snum = *((int64_t *) value);
break;
}
--
2.47.3
Reply all
Reply to author
Forward
0 new messages