Skip to content

Commit 595bcda

Browse files
feraralashkarcarlescufi
authored andcommitted
lib: os: dec: add misra-c2012 compliance changes
1. change explicit type cast of essential character type, complying with required [misra-c2012-10.2] rule which states; Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations, and 2. add explicit boolean type to 'if' statement controlling expression, consolidating it with 'buflen' type, thus improving code readability and maintainability , complying with required [misra-c2012-14.4] rule which states; ; The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially boolean type, and 3. add enclosing parentheses enforcing and clarifying precedence of operators, improving code readability and maintainability, complying with *advisory* [misra-c2012-12.1] rule which states; The precedence of operators within expressions should be made explicit. Found as a coding guideline violation (Rules 10.2, 14.4), and coding guideline recommendation (Rule 12.1) by static code scanning tool. Note: Tested on STM32L5 Nucleo-144 board (stm32l552xx). Signed-off-by: ferar alashkar <[email protected]>
1 parent dddc034 commit 595bcda

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/os/dec.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ uint8_t u8_to_dec(char *buf, uint8_t buflen, uint8_t value)
1212
uint8_t num_digits = 0;
1313
uint8_t digit;
1414

15-
while (buflen > 0 && divisor > 0) {
15+
while ((buflen > 0) && (divisor > 0)) {
1616
digit = value / divisor;
17-
if (digit != 0 || divisor == 1 || num_digits != 0) {
18-
*buf = (char)digit + '0';
17+
if ((digit != 0) || (divisor == 1) || (num_digits != 0)) {
18+
*buf = digit + (char)'0';
1919
buf++;
2020
buflen--;
2121
num_digits++;
@@ -25,7 +25,7 @@ uint8_t u8_to_dec(char *buf, uint8_t buflen, uint8_t value)
2525
divisor /= 10;
2626
}
2727

28-
if (buflen) {
28+
if (buflen != 0) {
2929
*buf = '\0';
3030
}
3131

0 commit comments

Comments
 (0)