Skip to content

Commit

Permalink
HV:lib:fix "signed/unsigned conversion without cast"
Browse files Browse the repository at this point in the history
Misra C required signed/unsigned conversion with cast.

V1->V2:
  a.split patch to patch series

V2->V3:
  a.change the uint64_t type numeric constant's suffix from U to UL

Signed-off-by: Huihuang Shi <huihuang.shi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
  • Loading branch information
Shawnshh authored and lijinxia committed Jul 4, 2018
1 parent 2ffa69c commit ac7ba6c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion hypervisor/include/lib/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef _Bool bool;
#endif

#ifndef UINT64_MAX
#define UINT64_MAX (-1UL)
#define UINT64_MAX (0xffffffffffffffffUL)
#endif

#endif /* ASSEMBLER */
Expand Down
24 changes: 13 additions & 11 deletions hypervisor/lib/div.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ int udiv32(uint32_t dividend, uint32_t divisor, struct udiv_result *res)
{

/* initialize the result */
res->q.dwords.low = res->r.dwords.low = 0;
res->q.dwords.low = 0U;
res->r.dwords.low = 0U;
/* test for "division by 0" condition */
if (divisor == 0) {
res->q.dwords.low = 0xffffffff;
if (divisor == 0U) {
res->q.dwords.low = 0xffffffffU;
return !0;
}
/* trivial case: divisor==dividend */
Expand All @@ -66,15 +67,16 @@ int udiv64(uint64_t dividend, uint64_t divisor, struct udiv_result *res)
uint64_t bits;

/* initialize the result */
res->q.qword = res->r.qword = 0;
res->q.qword = 0UL;
res->r.qword = 0UL;
/* test for "division by 0" condition */
if (divisor == 0) {
res->q.qword = 0xffffffffffffffffull;
if (divisor == 0UL) {
res->q.qword = 0xffffffffffffffffUL;
return -1;
}
/* trivial case: divisor==dividend */
if (divisor == dividend) {
res->q.qword = 1;
res->q.qword = 1UL;
return 0;
}
/* trivial case: divisor>dividend */
Expand All @@ -85,7 +87,7 @@ int udiv64(uint64_t dividend, uint64_t divisor, struct udiv_result *res)
/* simplified case: only 32 bit operands Note that the preconditions
* for do_udiv32() are fulfilled, since the tests were made above.
*/
if (((divisor >> 32) == 0) && ((dividend >> 32) == 0))
if (((divisor >> 32UL) == 0UL) && ((dividend >> 32UL) == 0UL))
return do_udiv32((uint32_t) dividend, (uint32_t) divisor, res);

/* dividend is always greater than or equal to the divisor. Neither
Expand All @@ -103,9 +105,9 @@ int udiv64(uint64_t dividend, uint64_t divisor, struct udiv_result *res)
dividend -= divisor;
res->q.qword |= mask;
}
divisor >>= 1;
mask >>= 1;
} while ((bits-- != 0UL) && (dividend != 0));
divisor >>= 1UL;
mask >>= 1UL;
} while ((bits-- != 0UL) && (dividend != 0UL));

res->r.qword = dividend;
return 0;
Expand Down

0 comments on commit ac7ba6c

Please sign in to comment.