Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MISRA C 2012 Rule 14.2 #861

Merged
merged 4 commits into from
Nov 24, 2023
Merged

Conversation

chinglee-iot
Copy link
Member

@chinglee-iot chinglee-iot commented Oct 25, 2023

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

  • Use break instead of second clause condition to escape from the loop.

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:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

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
Copy link

codecov bot commented Oct 25, 2023

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 ⚠️
Additional details and impacted files
@@            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 Coverage Δ
unittests 93.64% <33.33%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chinglee-iot chinglee-iot requested a review from a team as a code owner November 6, 2023 08:54
Copy link

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

@aggarg aggarg merged commit ac43135 into FreeRTOS:main Nov 24, 2023
15 of 17 checks passed
@aggarg aggarg deleted the fix-misra-14.2 branch November 24, 2023 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants