FreeRTOS / FreeRTOS-Kernel

FreeRTOS kernel files only, submoduled into https://github.com/FreeRTOS/FreeRTOS and various other repos.
https://www.FreeRTOS.org
MIT License
2.76k stars 1.12k forks source link

Fix MISRA C 2012 Rule 14.2 #861

Closed chinglee-iot closed 11 months ago

chinglee-iot commented 1 year ago

Fix MISRA C 2012 Rule 14.2

Description

MISRA C 2012 Rule 14.2

A for loop shall be well-formed

MISRA violation The MISRA rule requires the object in the second clause should not be modified. This makes the code easier to review and analyse. The following is an example of violation. The variable xOutputBufferFull in the second clause is modified in the for loop body.

for( x = 0; ( x < uxArraySize ) && ( xOutputBufferFull == pdFALSE ); x++ )
{
    ...
    xOutputBufferFull = pdTRUE;
    ...
}

Fix in this PR

In the above example, use a break statement instead of the second clause condition to escape from the for loop.

for( x = 0; x < uxArraySize; x++ )
{
    ...
    xOutputBufferFull = pdTRUE;
    ...
   if( xOutputBufferFull  == pdTRUE )
   {
        break;
   }
}

Test Steps

N/A

Checklist:

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

codecov[bot] commented 1 year ago

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (09c4c4b) 93.67% compared to head (7130601) 93.64%.

Files Patch % Lines
tasks.c 33.33% 1 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #861 +/- ## ========================================== - Coverage 93.67% 93.64% -0.03% ========================================== Files 6 6 Lines 3177 3179 +2 Branches 884 885 +1 ========================================== + Hits 2976 2977 +1 - Misses 94 95 +1 Partials 107 107 ``` | [Flag](https://app.codecov.io/gh/FreeRTOS/FreeRTOS-Kernel/pull/861/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FreeRTOS) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/FreeRTOS/FreeRTOS-Kernel/pull/861/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FreeRTOS) | `93.64% <33.33%> (-0.03%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FreeRTOS#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

sonarcloud[bot] commented 11 months ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication