mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-23 01:37:44 +00:00
HV: treewide: terminate 'if .. else if' constructs with 'else'
MISRA C requires that a 'if' statement followed by one or more 'else if' statement shall be terminated by an 'else' statement which contains either side-effect or a comment, to ensure that conditions are considered exhaustively. Note that a simple 'if' statement is not required to be terminated by 'else'. This patch fixes such violations by either refactoring the code or add the 'else' statement with either a comment (describing why this case can be skipped) or logging the event. It may not be satisfactory for the release version where logging is no-op, but properly handling these non-trivial cases is out of the scope of this patch. v1 -> v2: * Fix unintended semantic changes in add_(msix|intx)_remapping and io_instr_vmexit_handler. * Simplify boolean checks in vpic_ocw2. * Rephrase the comment in strtol_deci. Signed-off-by: Junjie Mao <junjie.mao@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
@@ -161,8 +161,8 @@ static const char *get_flags(const char *s, int *flags)
|
||||
static const char *get_length_modifier(const char *s,
|
||||
int *flags, uint64_t *mask)
|
||||
{
|
||||
/* check for h[h] (char/short) */
|
||||
if (*s == 'h') {
|
||||
/* check for h[h] (char/short) */
|
||||
s++;
|
||||
if (*s == 'h') {
|
||||
*flags |= PRINT_FLAG_CHAR;
|
||||
@@ -173,7 +173,7 @@ static const char *get_length_modifier(const char *s,
|
||||
*mask = 0x0000FFFF;
|
||||
}
|
||||
} else if (*s == 'l') {
|
||||
/* check for l[l] (long/long long) */
|
||||
/* check for l[l] (long/long long) */
|
||||
s++;
|
||||
if (*s == 'l') {
|
||||
*flags |= PRINT_FLAG_LONG_LONG;
|
||||
@@ -181,6 +181,8 @@ static const char *get_length_modifier(const char *s,
|
||||
} else {
|
||||
*flags |= PRINT_FLAG_LONG;
|
||||
}
|
||||
} else {
|
||||
/* No length modifiers found. */
|
||||
}
|
||||
|
||||
return s;
|
||||
@@ -375,6 +377,8 @@ static int print_decimal(struct print_param *param, int64_t value)
|
||||
} else if ((param->vars.flags & PRINT_FLAG_SPACE) != 0) {
|
||||
param->vars.prefix = " ";
|
||||
param->vars.prefixlen = 1;
|
||||
} else {
|
||||
/* No prefix specified. */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -662,6 +666,8 @@ static int charmem(int cmd, const char *s, int sz, void *hnd)
|
||||
s++;
|
||||
n++;
|
||||
}
|
||||
} else {
|
||||
/* sz == 0, no copy needed. */
|
||||
}
|
||||
|
||||
param->wrtn += n;
|
||||
|
@@ -37,7 +37,10 @@ long strtol_deci(const char *nptr)
|
||||
} else if (c == '+') {
|
||||
c = *s;
|
||||
s++;
|
||||
} else {
|
||||
/* No sign character. */
|
||||
}
|
||||
|
||||
/*
|
||||
* Compute the cutoff value between legal numbers and illegal
|
||||
* numbers. That is the largest legal value, divided by the
|
||||
@@ -63,8 +66,7 @@ long strtol_deci(const char *nptr)
|
||||
do {
|
||||
if (c >= '0' && c <= '9') {
|
||||
c -= '0';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if (c >= base) {
|
||||
@@ -72,8 +74,7 @@ long strtol_deci(const char *nptr)
|
||||
}
|
||||
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) {
|
||||
any = -1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
any = 1;
|
||||
acc *= base;
|
||||
acc += c;
|
||||
@@ -87,6 +88,9 @@ long strtol_deci(const char *nptr)
|
||||
acc = (neg != 0) ? LONG_MIN : LONG_MAX;
|
||||
} else if (neg != 0) {
|
||||
acc = -acc;
|
||||
} else {
|
||||
/* There is no overflow and no leading '-' exists. In such case
|
||||
* acc already holds the right number. No action required. */
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
Reference in New Issue
Block a user