remove theoretical uninitialised variable use in infer_cpu_gic_id

The C semantics used by our binary correctness mechanism understand
uninitialised variables as non-deterministic assignment. The translation
to a simplified form suitable for further analysis occurs on a
per-function basis which does not support non-determinism. This means
uninitialised local variables must not be used for decision making in
any function.

In infer_cpu_gic_id, 'target' is initialised in the loop, which will not
be executed if nirqs <= 0, after which the uninitialised 'target' is
examined. We address this by initialising 'target' to 0.

The overall C code is still safe, as infer_cpu_gic_id is only called
once in dist_init, where 0 < nirqs.
This commit is contained in:
Rafal Kolanski 2018-11-08 15:46:59 +11:00
parent 7d16e3dcae
commit d12bb374ab

View file

@ -53,7 +53,7 @@ BOOT_CODE static uint8_t
infer_cpu_gic_id(int nirqs)
{
word_t i;
uint32_t target;
uint32_t target = 0;
for (i = 0; i < nirqs; i += 4) {
target = gic_dist->targets[i >> 2];
target |= target >> 16;