Refactoring. Improve code reuse ratio.

Add ARRAY_SIZE() macro.

Use the new macro in all places where array size is calculated by
means of sizeof(array)/sizeof(array[0]).

Fix minor bugs and warnings in the affected code.

Signed-off-by: Alexander Amelkin <alexander@amelkin.msk.ru>
This commit is contained in:
Alexander Amelkin
2018-08-14 16:41:52 +03:00
parent 232773d171
commit bb1a4cc805
6 changed files with 16 additions and 16 deletions

View File

@@ -898,6 +898,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
uint8_t * fru_data;
uint32_t fru_len, i;
uint8_t tmp[2];
size_t chassis_type;
fru_len = 0;
@@ -931,10 +932,10 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru,
*/
i = 2;
printf(" Chassis Type : %s\n",
chassis_type_desc[fru_data[i] >
(sizeof(chassis_type_desc)/sizeof(chassis_type_desc[0])) - 1 ?
2 : fru_data[i]]);
chassis_type = (fru_data[i] > ARRAY_SIZE(chassis_type_desc) - 1)
? 2
: fru_data[i];
printf(" Chassis Type : %s\n", chassis_type_desc[chassis_type]);
i++;