commit f94b31189514cc79c1d5f0f75dca4df50236958b
parent cd1de99b9b465dcaccc9d7260f412eceed67307b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sun, 19 Jan 2025 14:07:33 +0100
objdump: Define log2(0) to be 0
From the math point of view log2(0) is not defined, and it is usually considered
infinite, but in our case it only can happen when sections have a 0 alignment, so
we can just return 0 in that case, because otherwise we would enter in an infinite
loop (the programming version of the math infinite?).
Diffstat:
1 file changed, 3 insertions(+), 0 deletions(-)
diff --git a/src/cmd/scc-objdump/main.c b/src/cmd/scc-objdump/main.c
@@ -129,6 +129,9 @@ logb2(unsigned val)
{
int n;
+ if (val == 0)
+ return 0;
+
for (n = 0; (val & 1) == 0; n++)
val >>= 1;
return n;