Skip to content

Commit bf6a474

Browse files
authored
Fix MISRA violations of 10.4 and 10.7 rules (#24)
1 parent 9316372 commit bf6a474

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Changes
66

7+
- [#24](https://github.com/FreeRTOS/backoffAlgorithm/pull/24) Fix MISRA 10.4 and 10.7 rule violations, and add documentation of MISRA compliance.
78
- [#18](https://github.com/FreeRTOS/backoffAlgorithm/pull/18), [#19](https://github.com/FreeRTOS/backoffAlgorithm/pull/19), and [#20](https://github.com/FreeRTOS/backoffAlgorithm/pull/20) Documentation fixes.
89

910
## v1.0.0 (December 2020)

MISRA.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# MISRA Compliance
2+
3+
The backoffAlgorithm library files conform to the [MISRA C:2012](https://www.misra.org.uk/MISRAHome/MISRAC2012/tabid/196/Default.aspx)
4+
guidelines, with some noted exceptions. Compliance is checked with Coverity static analysis.
5+
Deviations from the MISRA standard are listed below:
6+
7+
### Ignored by [Coverity Configuration](tools/coverity/misra.config)
8+
| Deviation | Category | Justification |
9+
| :-: | :-: | :-: |
10+
| Directive 4.9 | Advisory | Allow inclusion of function like macros. |
11+
| Rule 3.1 | Required | Allow nested comments. C++ style `//` comments are used in example code within Doxygen documentation blocks. |
12+
| Rule 2.4 | Advisory | Allow unused tags. Some compilers warn if types are not tagged. |
13+
14+
### Flagged by Coverity
15+
| Deviation | Category | Justification |
16+
| :-: | :-: | :-: |
17+
| Rule 8.7 | Advisory | API functions are not used by the library; however, they must be externally visible in order to be used by an application. |
18+

source/backoff_algorithm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ BackoffAlgorithmStatus_t BackoffAlgorithm_GetNextBackoff( BackoffAlgorithmContex
5252
* for the retry attempt. */
5353

5454
/* Choose a random value for back-off time between 0 and the max jitter value. */
55-
*pNextBackOff = ( uint16_t ) ( randomValue % ( pRetryContext->nextJitterMax + 1U ) );
55+
*pNextBackOff = ( uint16_t ) ( randomValue % ( pRetryContext->nextJitterMax + ( uint32_t ) 1U ) );
5656

5757
/* Increment the retry attempt. */
5858
pRetryContext->attemptsDone++;

source/include/backoff_algorithm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* @ingroup backoff_algorithm_constants
4141
* @brief Constant to represent unlimited number of retry attempts.
4242
*/
43-
#define BACKOFF_ALGORITHM_RETRY_FOREVER 0
43+
#define BACKOFF_ALGORITHM_RETRY_FOREVER ( 0U )
4444

4545
/**
4646
* @ingroup backoff_algorithm_enum_types

tools/coverity/misra.config

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// MISRA C-2012 Rules
2+
3+
{
4+
version : "2.0",
5+
standard : "c2012",
6+
title: "Coverity MISRA Configuration",
7+
deviations : [
8+
// Disable the following rules.
9+
{
10+
deviation: "Directive 4.9",
11+
reason: "Allow inclusion of function like macros. Logging is done using function like macros."
12+
},
13+
{
14+
deviation: "Rule 2.4",
15+
reason: "Allow unused tags. Some compilers warn if types are not tagged."
16+
},
17+
{
18+
deviation: "Rule 3.1",
19+
reason: "Allow nested comments. Documentation blocks contain comments for example code."
20+
}
21+
]
22+
}

0 commit comments

Comments
 (0)