Electronics > Microcontrollers

MISRA C & OpenSource

<< < (8/8)

JPortici:
for example, both GCC (version included in XC16 v1.70 is 4.5.1) and CPPCheck are failing to recognize that this statement

--- Code: ---flashStatus.flags.writeSetupPending;
--- End code ---
has not effect. This was making me crazy.

definition

--- Code: ---typedef volatile struct {
  union {
    uint16_t word;
    struct {
      unsigned readSetupPending:1;  //Setup Read pending
      unsigned eraseSetupPending:1; //Setup Erase pending
      unsigned writeSetupPending:1; //Setup Write pending
      unsigned :2;
      unsigned readUDIDPending:1;   //UDID Read Pending
      unsigned :6;
      unsigned resetPending:1;      //Reset Pending after Page Erase
      unsigned setupDataReady:1;    //Setup Data Ready
      unsigned setupUpdated:1;      //Setup Updated
      unsigned error:1;             //Flash Programming Error
    };
  } flags;
  int16_t flashSaveCnt;
} flashStatus_t;
--- End code ---

newbrain:

--- Quote from: JPortici on October 15, 2021, 08:18:08 am ---for example, both GCC (version included in XC16 v1.70 is 4.5.1) and CPPCheck are failing to recognize that this statement

--- Code: ---flashStatus.flags.writeSetupPending;
--- End code ---
has not effect. This was making me crazy.

definition

--- Code: ---typedef volatile struct {
[...]
} flashStatus_t;
--- End code ---

--- End quote ---
But it has an effect!
Since the typedef is volatile, the expression statement represents a read access to writeSetupPending and the volatile semantic forces the access to happen.

Removing volatile, gcc and clang warn about the statement having no effect, if one uses -Wall, or the specific -Wunused-value flag.

JPortici:

--- Quote from: newbrain on October 15, 2021, 09:48:16 am ---
--- Quote from: JPortici on October 15, 2021, 08:18:08 am ---for example, both GCC (version included in XC16 v1.70 is 4.5.1) and CPPCheck are failing to recognize that this statement

--- Code: ---flashStatus.flags.writeSetupPending;
--- End code ---
has not effect. This was making me crazy.

definition

--- Code: ---typedef volatile struct {
[...]
} flashStatus_t;
--- End code ---

--- End quote ---
But it has an effect!
Since the typedef is volatile, the expression statement represents a read access to writeSetupPending and the volatile semantic forces the access to happen.

Removing volatile, gcc and clang warn about the statement having no effect, if one uses -Wall, or the specific -Wunused-value flag.


--- End quote ---

Ah, of course.
Disregard this particular example then

SiliconWizard:

--- Quote from: semir-t on October 15, 2021, 06:29:00 am ---Yes, I assume that commercial applications are way better and we do have one in mind. Problem is that this application is linked to the PC, so only one person can use it. So our idea was to try to get some free version that would help our team develop the code  which will be as closely as possible compliant with the MISRA standard.  Frequently we would use commercial app to solve all the issues.

--- End quote ---

As you can see, the MISRA addon of Cppcheck gives a lot of false positives. You can actually run it on the official MISRA examples I linked to, and see for yourself. It does spot a lot of true violations, but also find ones that aren't... May still be kind of useful as first check, but it's likely to make you waste a lot of time.

If you use Eclipse (which I don't), there is a plugin that you may try as well: https://github.com/stkim123/kr.ac.jbnu.ssel.misrac

Kalvin:
In C, the switch statement's default is supposed to be followed by a colon. A syntax error like this may/will affect the parser/analyzer, so all syntax errors need to be fixed first before analyzing the actual analyzer output.

Navigation

[0] Message Index

[*] Previous page

There was an error while thanking
Thanking...
Go to full version