Skip to content

Commit

Permalink
Fix MISRA C 2012 deviations (#92)
Browse files Browse the repository at this point in the history
* Fix MISRA deviations

* Not to apply operators to an expression of pointer type

* Not to use reserved identifier on internal variable

* Fix CI build flow

* Fix spelling

* Fix more rule 18.4 deviations

* Rename internal variable

* Not using negative index in implementation

* Fix more rule 18.4 deviations

* Update format

* Update CMakeLists.txt

* Update MISRA comments

* Use parentheses to specify operator order

* Fix typo

* Use negative index in the implementation

* Add assertion to ensure pBufCur points to the same array

---------

Co-authored-by: Ubuntu <[email protected]>
  • Loading branch information
chinglee-iot and Ubuntu authored Mar 5, 2024
1 parent dbe5583 commit dc530f7
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 144 deletions.
3 changes: 2 additions & 1 deletion .github/.cSpellWords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ decihours
Decihours
DECIHOURS
DNDEBUG
DUNITY
DSIGV
DUNITY
DUNITTEST
Ecjuve
EKHX
getpacketid
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
cmake -S test -B build/ \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_UNIT_TESTS=ON \
-DUNITTEST=ON \
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -DNDEBUG -DLOGGING_LEVEL_DEBUG=1'
make -C build/ all
Expand Down
10 changes: 10 additions & 0 deletions MISRA.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ _Ref 5.4.1_
in use and changing the name will break existing user projects. Thus, for
backwards compatibility, the macro is not modified and kept as is and the
deviation is suppressed.

_Ref 18.2.1_

- MISRA Rule 18.2 states that two pointers may only be subtracted if they point
to elements of the same array. In this library, array of bytes are used to process
data. Functions which fill the arrays with data update an index to an offset.
To know the amount of data added to the array, the beginning address of the array has
to be subtracted from the index. It is manually verified that the index will always be
within bounds of the array. However, Coverity is flagging this as a deviation. Thus, we
are suppressing it.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ include paths required to build this library.

1. Go to the root directory of this repository.

1. Run the _cmake_ command: `cmake -S test -B build -DBUILD_UNIT_TESTS=ON`.
1. Run the _cmake_ command: `cmake -S test -B build -DUNITTEST=ON`.

1. Run this command to build the library and unit tests: `make -C build all`.

Expand Down
12 changes: 6 additions & 6 deletions source/include/sigv4_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@
*/
typedef struct SigV4DateTime
{
int32_t tm_year; /**< Year (1900 or later) */
int32_t tm_mon; /**< Month (1 to 12) */
int32_t tm_mday; /**< Day of Month (1 to 28/29/30/31) */
int32_t tm_hour; /**< Hour (0 to 23) */
int32_t tm_min; /**< Minutes (0 to 59) */
int32_t tm_sec; /**< Seconds (0 to 60) */
int32_t year; /**< Year (1900 or later) */
int32_t mon; /**< Month (1 to 12) */
int32_t mday; /**< Day of Month (1 to 28/29/30/31) */
int32_t hour; /**< Hour (0 to 23) */
int32_t min; /**< Minutes (0 to 59) */
int32_t sec; /**< Seconds (0 to 60) */
} SigV4DateTime_t;

/**
Expand Down
Loading

0 comments on commit dc530f7

Please sign in to comment.