GCC 15 identifies this with:
lib/human.c: In function 'human_readable':
lib/human.c:295:32: warning: 'exponent_max' may be used uninitialized
295 | while (base <= amt && exponent < exponent_max);
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
This issue also caused coreutils tests/dd/dd-stats.sh to fail
* lib/human.c (human_readable): Move initialization before
the gotos which might skip it.
---
ChangeLog | 6 ++++++
lib/human.c | 9 +++++----
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b2f3d49805..98a9146cb9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-12-10 Pádraig Brady <[email protected]>
+
+ human: fix UMR introduced in recent change
+ * lib/human.c (human_readable): Move initialization before
+ the gotos which might skip it.
+
2025-12-10 Bruno Haible <[email protected]>
sigsegv: Reduce scope of local variables.
diff --git a/lib/human.c b/lib/human.c
index 9e2cf0958f..38eddaf53e 100644
--- a/lib/human.c
+++ b/lib/human.c
@@ -188,6 +188,11 @@ human_readable (uintmax_t n, char *buf, int opts,
2 means adjusted N == AMT.TENTHS + 0.05;
3 means AMT.TENTHS + 0.05 < adjusted N < AMT.TENTHS + 0.1. */
int rounding;
+
+ int exponent = -1;
+ int exponent_max = sizeof power_letter - 1;
+ char const *integerlim;
+
if (to_block_size <= from_block_size)
{
if (from_block_size % to_block_size == 0)
@@ -213,10 +218,6 @@ human_readable (uintmax_t n, char *buf, int opts,
goto use_integer_arithmetic;
}
- int exponent = -1;
- int exponent_max = sizeof power_letter - 1;
- char const *integerlim;
-
{
/* Either the result cannot be computed easily using uintmax_t,
or from_block_size is zero. Fall back on floating point.
--
2.51.1