hv: treewide: fix 'Potential side effect problem in expression'

MISRA-C requirement:
The value of an expression shall be the same under any order of
evaluation.
The order in which side effects take place is unspecified and may lead
to unexpected results.

This patch add a temporary variable for temporary storage to avoid the
side effects of evaluation order.

Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Shiqing Gao
2018-08-07 10:38:12 +08:00
committed by lijinxia
parent b1612e3072
commit c0544c9d36
2 changed files with 15 additions and 4 deletions

View File

@@ -14,11 +14,13 @@ static int charout(int cmd, const char *s_arg, uint32_t sz_arg, void *hnd)
int *nchars = (int *)hnd;
/* working pointer */
const char *p = s;
int len;
/* copy mode ? */
if (cmd == PRINT_CMD_COPY) {
if (sz > 0U) { /* copy 'sz' characters */
s += console_write(s, sz);
len = console_write(s, sz);
s += len;
}
*nchars += (s - p);