Skip to content

Commit

Permalink
lib: printk: Make if/iterations evaluate boolean operands
Browse files Browse the repository at this point in the history
MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
  • Loading branch information
ceolin authored and nashif committed Mar 27, 2019
1 parent 2df02cc commit c2b2515
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/os/printk.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,10 @@ static void _printk_hex_ulong(out_func_t out, void *ctx,
int remaining = 16; /* 16 digits max */
int digits = 0;

for (; size; size--) {
for (; size != 0; size--) {
char nibble = (num >> ((size - 1) << 2) & 0xf);

if (nibble || found_largest_digit || size == 1) {
if (nibble != 0 || found_largest_digit != 0 || size == 1) {
found_largest_digit = 1;
nibble += nibble > 9 ? 87 : 48;
out((int)nibble, ctx);
Expand Down Expand Up @@ -459,7 +459,7 @@ static void _printk_dec_ulong(out_func_t out, void *ctx,
}

while (pos >= 9) {
if (found_largest_digit || remainder > pos) {
if (found_largest_digit != 0 || remainder > pos) {
found_largest_digit = 1;
out((int)((remainder / (pos + 1)) + 48), ctx);
digits++;
Expand Down Expand Up @@ -490,7 +490,7 @@ struct str_context {

static int str_out(int c, struct str_context *ctx)
{
if (!ctx->str || ctx->count >= ctx->max) {
if (ctx->str == NULL || ctx->count >= ctx->max) {
ctx->count++;
return c;
}
Expand Down

0 comments on commit c2b2515

Please sign in to comment.