From 9c133c7bbcca2e37db72ba42cbc2d868c9e505ef Mon Sep 17 00:00:00 2001 From: "Li, Fei1" Date: Tue, 4 Dec 2018 22:00:58 +0800 Subject: [PATCH] hv: lib: refine print_decimal Align the calculate logic to make it simpler. Tracked-On: #861 Signed-off-by: Li, Fei1 --- hypervisor/lib/sprintf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hypervisor/lib/sprintf.c b/hypervisor/lib/sprintf.c index 8947dc7ec..6ef121cb8 100644 --- a/hypervisor/lib/sprintf.c +++ b/hypervisor/lib/sprintf.c @@ -348,17 +348,17 @@ static void print_decimal(struct print_param *param, int64_t value) v.qword = v.qword / 10UL; } + nv.dwords.low = v.dwords.low; /* process 32 bit (or reduced 64 bit) value */ do { /* determine digits from right to left. The compiler should be * able to handle a division and multiplication by the constant * 10. */ - nv.dwords.low = v.dwords.low / 10U; pos--; - *pos = (v.dwords.low - (10U * nv.dwords.low)) + '0'; - v.dwords.low = nv.dwords.low; - } while (v.dwords.low != 0U); + *pos = (char)(nv.dwords.low % 10U) + '0'; + nv.dwords.low = nv.dwords.low / 10U; + } while (nv.dwords.low != 0U); /* assign parameter and apply width and precision */ param->vars.value = pos;