Lee Leahy has uploaded a new change for review. ( https://review.coreboot.org/19643 )
Change subject: drivers/storage: Fix array references ......................................................................
drivers/storage: Fix array references
Reduce the loop index by 1 to make coverity happy. The analysis indicated that it was possible to exit the loop without meeting the condition. While this would not happen in the real world the reference beyond the end of the arrays can be eliminated by reducing the index by 1.
Coverity Issues: * 1374931 * 1374932 * 1374933 * 1374934
TEST=Build and run on Galileo Gen2
Change-Id: Ie5c96e78417b667438a00ee22c70894a00d13291 Signed-off-by: Lee Leahy Leroy.P.Leahy@intel.com --- M src/drivers/storage/storage.c 1 file changed, 7 insertions(+), 5 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/43/19643/1
diff --git a/src/drivers/storage/storage.c b/src/drivers/storage/storage.c index 57477f9..daab655 100644 --- a/src/drivers/storage/storage.c +++ b/src/drivers/storage/storage.c @@ -72,6 +72,7 @@ uint64_t capacity; uint64_t decimal_divisor; const char *decimal_units; + int entries; uint64_t hex_divisor; const char *hex_units; int index; @@ -86,9 +87,9 @@ separator = ": ";
/* Determine the decimal divisor for the capacity */ - ASSERT(ARRAY_SIZE(decimal_capacity_table) - == ARRAY_SIZE(decimal_unit_name)); - for (index = 0; index < ARRAY_SIZE(decimal_capacity_table); index++) { + entries = ARRAY_SIZE(decimal_capacity_table); + ASSERT(entries == ARRAY_SIZE(decimal_unit_name)); + for (index = 0; index < entries - 1; index++) { if (capacity >= decimal_capacity_table[index]) break; } @@ -96,8 +97,9 @@ decimal_units = decimal_unit_name[index];
/* Determine the hex divisor for the capacity */ - ASSERT(ARRAY_SIZE(hex_capacity_table) == ARRAY_SIZE(hex_unit_name)); - for (index = 0; index < ARRAY_SIZE(hex_capacity_table); index++) { + entries = ARRAY_SIZE(hex_capacity_table); + ASSERT(entries == ARRAY_SIZE(hex_unit_name)); + for (index = 0; index < entries - 1; index++) { if (capacity >= hex_capacity_table[index]) break; }