Skip to content

Commit

Permalink
lib: add default labels and comments to switch statements
Browse files Browse the repository at this point in the history
According to the Zephyr Coding Guideline all switch statements
shall be well-formed.
Added a default labels to switch-clauses without them.
Added comments to the empty default cases.

Found as a coding guideline violation (MISRA R16.1) by static
coding scanning tool.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
  • Loading branch information
maksimmasalski authored and galak committed Jun 4, 2021
1 parent 82ec1c0 commit a61edd4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/libc/minimal/source/stdlib/atoi.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ int atoi(const char *s)
break; /* artifact to quiet coverity warning */
case '+':
s++;
default:
/* Add an empty default with break, this is a defensive programming.
* Static analysis tool won't raise a violation if default is empty,
* but has that comment.
*/
break;
}
/* Compute n as a negative number to avoid overflow on INT_MIN */
while (isdigit(*s)) {
Expand Down
14 changes: 14 additions & 0 deletions lib/os/cbprintf_complete.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,10 @@ static inline const char *extract_specifier(struct conversion *conv,
unsupported = sizeof(ptrdiff_t) > 4;
break;
default:
/* Add an empty default with break, this is a defensive
* programming. Static analysis tool won't raise a violation
* if default is empty, but has that comment.
*/
break;
}
} else {
Expand Down Expand Up @@ -1303,6 +1307,10 @@ static inline void store_count(const struct conversion *conv,
*(ptrdiff_t *)dp = (ptrdiff_t)count;
break;
default:
/* Add an empty default with break, this is a defensive programming.
* Static analysis tool won't raise a violation if default is empty,
* but has that comment.
*/
break;
}
}
Expand Down Expand Up @@ -1665,6 +1673,12 @@ int cbvprintf(cbprintf_cb out, void *ctx, const char *fp, va_list ap)
&sign, buf, &bpe);
}
break;
default:
/* Add an empty default with break, this is a defensive
* programming. Static analysis tool won't raise a violation
* if default is empty, but has that comment.
*/
break;
}

/* If we don't have a converted value to emit, move
Expand Down
6 changes: 6 additions & 0 deletions lib/os/fdtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ int fcntl(int fd, int cmd, ...)
/* Not implemented so far. */
errno = EINVAL;
return -1;
default:
/* Add an empty default with break, this is a defensive programming.
* Static analysis tool won't raise a violation if default is empty,
* but has that comment.
*/
break;
}

/* The rest of commands are per-fd, handled by ioctl vmethod. */
Expand Down

0 comments on commit a61edd4

Please sign in to comment.