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++;

View File

@@ -1027,9 +1027,7 @@ static void lanp_print_usage(int cmd)
printf("\n available parameters:\n");
/* 'save' shall use 'write' filter, since it outputs a block
* of 'set's */
ipmi_cfgp_usage(lan_cfgp,
sizeof(lan_cfgp)/sizeof(lan_cfgp[0]),
cmd != LANP_CMD_PRINT);
ipmi_cfgp_usage(lan_cfgp, ARRAY_SIZE(lan_cfgp), cmd != LANP_CMD_PRINT);
}
}
@@ -1161,8 +1159,8 @@ ipmi_lan6_main(struct ipmi_intf *intf, int argc, char **argv)
*/
ipmi_cfgp_init(&ctx, lan_cfgp,
sizeof(lan_cfgp)/sizeof(lan_cfgp[0]), "lan6 set nolock",
lanp_ip6_cfgp, &lp);
ARRAY_SIZE(lan_cfgp), "lan6 set nolock",
lanp_ip6_cfgp, &lp);
ret = ipmi_cfgp_parse_sel(&ctx, argc, (const char **)argv, &sel);
if (ret == -1) {