[libblockdev 1/2] Omit i < NUM_PREFIXES check.

Vratislav Podzimek vpodzime at redhat.com
Wed Sep 3 13:20:16 UTC 2014

On Tue, 2014-09-02 at 22:13 -0400, mulhern wrote:
> Because the size we are dealing with is an unsigned 64 bit integer
> the maximum representable value is 2^64 - 1 which means that
> INT_LT_FLOAT(1024, value) must be false when i is 6. Therefore, i
> can never reach NUM_PREFIXES, i.e., 7, so the check is pointless.
> If i could reach NUM_PREFIXES then there would exist a path such that
> i was 7 when size_prefixes[i] is evaluated, which would be an
> access outside the bounds of the array.
I'm not sure I (and all the other people reading the code) want to make
this mental exercise every time I (they) read the code. If you really
don't like that check or think it is performance issue, please add a
descriptive comment above the for-cycle explaining why we don't have to
check the value of the 'i' variable.

Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic

More information about the anaconda-patches mailing list