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

@@ -241,12 +241,12 @@ serial_bm_open(struct ipmi_intf * intf)
return -1;
}
for (i = 0; i < sizeof(rates) / sizeof(rates[0]); i++) {
for (i = 0; i < ARRAY_SIZE(rates); i++) {
if (rates[i].baudrate == rate) {
break;
}
}
if (i >= sizeof(rates) / sizeof(rates[0])) {
if (i >= ARRAY_SIZE(rates)) {
lprintf(LOG_ERR, "Unsupported baud rate %i specified", rate);
return -1;
}

View File

@@ -149,7 +149,7 @@ ipmi_serial_term_open(struct ipmi_intf * intf)
struct termios ti;
unsigned int rate = 9600;
char *p;
int i;
size_t i;
if (!intf->devfile) {
lprintf(LOG_ERR, "Serial device is not specified");
@@ -188,12 +188,12 @@ ipmi_serial_term_open(struct ipmi_intf * intf)
return -1;
}
for (i = 0; i < sizeof(rates) / sizeof(rates[0]); i++) {
for (i = 0; i < ARRAY_SIZE(rates); i++) {
if (rates[i].baudrate == rate) {
break;
}
}
if (i >= sizeof(rates) / sizeof(rates[0])) {
if (i >= ARRAY_SIZE(rates)) {
lprintf(LOG_ERR, "Unsupported baud rate %i specified", rate);
return -1;
}