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 10.3 errors #860

Merged
merged 10 commits into from
Nov 28, 2023

Conversation

chinglee-iot
Copy link
Member

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

Fix MISRA C 2012 Rule 10.3 errors

Description

MISRA C 2012 Rule 10.3

The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category.

MISRA violation
The size of constant with suffix UL is different for different compiler.

For example, sizeof( 0x01000000UL ) is 4 if using 32-bits GCC compiler. However, it is 8 if using 64-btis GCC compiler. Therefore, assigning a constant with suffix UL to a uint32_t can cause implicit conversion which may lead to unintended result.

The following is an example of the violation. Size of constant eventEVENT_BITS_CONTROL_BYTES is 8 with 64-bits GCC compiler. The statement uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES; causes implicit conversion.

#define eventEVENT_BITS_CONTROL_BYTES 0xff000000UL

UBaseType_t uxReturn;
...
uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;

Fix In this PR

  • Use type casting for constant type.
  • Use type casting to prevent assign value to an object with narrower essential type.

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

All modified and coverable lines are covered by tests ✅

Comparison is base (76f3aa5) 93.64% compared to head (9a25940) 93.64%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #860   +/-   ##
=======================================
  Coverage   93.64%   93.64%           
=======================================
  Files           6        6           
  Lines        3179     3179           
  Branches      885      885           
=======================================
  Hits         2977     2977           
  Misses         95       95           
  Partials      107      107           
Flag Coverage Δ
unittests 93.64% <100.00%> (ø)

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.

tasks.c Show resolved Hide resolved
@chinglee-iot chinglee-iot requested a review from a team as a code owner October 30, 2023 07:23
@chinglee-iot chinglee-iot requested a review from moninom1 October 30, 2023 07:26
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

@chinglee-iot chinglee-iot merged commit ce88ade into FreeRTOS:main Nov 28, 2023
17 checks passed
@aggarg aggarg deleted the fix-misra-10.3 branch November 28, 2023 09:25
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