ptgen: fix misprint and simplify calculation a bit
authorMikhail Kshevetskiy <[email protected]>
Fri, 10 Jan 2025 08:23:54 +0000 (11:23 +0300)
committerDaniel Golle <[email protected]>
Tue, 23 Sep 2025 22:15:33 +0000 (23:15 +0100)
2 << ((10 * exp) - 1) is equal to 1 << (10 * exp). This allows us
simplify a formula and remove extra if.

Signed-off-by: Mikhail Kshevetskiy <[email protected]>
src/ptgen.c

index c7d6bc0ae4e1853b6af568292c53313d90700007..e5fee0debb46863c9ac18e6947be91c7f32e0528 100644 (file)
@@ -203,10 +203,8 @@ static long to_kbytes(const char *string)
                return 0;
        }
 
-       /* result: number + 1024^(exp) */
-       if (exp == 0)
-               return result;
-       return result * (2 << ((10 * exp) - 1));
+       /* result: number * 1024^(exp) */
+       return result * (1 << (10 * exp));
 }
 
 /* convert the sector number into a CHS value for the partition table */