Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





  Writing a FLOSS checker for MISRA-C
Posted by: pkrebs - 28-02-2012, 08:44 AM - Forum: General Questions - Replies (1)

Good morning,

I'm (once more) thinking of implementing a static analysis tool for checking C sources against the MISRA-C:200 rules and release it as FLOSS (e. g. under GPL or a similar permissive license). However, I would need some questions answered before I can meaningfully undertake this task - I figure, that this is the best place to ask. What I would like to know is:

- Are there any legal restrictions when implementing a static analyser that claims to check the MISRA rules, i. e. is it even allowed to advertise this as a feature?
- Is it allowed to release such an analyser under a FLOSS license? The only problem I can think of is, that it is in principle possible to "reverse engineer" the rules out of the tool's source code, which could be seen as distributing the guidelines "for free".
- If a FLOSS release is permitted, are there any legal obligations to inform the MISRA Consortium of the release and subsequent additions to the tool (e. g. implementation of further MISRA rules)?

If someone can think of additional problems considering MISRA and FLOSS, don't hesitate to mention them (I am by no means a FLOSS license expert, those are just the problems I can immediately see).

Many thanks in advance for all pointers and answers.

Best Regards,

Peter

Print this item

  Does this code violate rule #8.7?
Posted by: gs - 15-02-2012, 07:30 PM - Forum: 6.8 Declarations and Definitions - Replies (3)

Given this example

Code:
file1.c:
        static int i;
        int j[1] = { i };
file2.c:
        extern int j[1];
        void f()
            {
            int k = j[0];
            }
Does this code violate rule #8.7, "Objects shall be defined at block scope if they are only accessed from within a single function"?

Print this item

  9.1 and Addressing
Posted by: gs - 13-02-2012, 10:37 PM - Forum: 6.9 Initialisation - Replies (1)

Suppose I have two functions:

Code:
void f( int * );
void g( const int * );
and the following usage:
Code:
void h()
{
int i;
int j;

f( &i );
g( &j );
}
Do these violate rule #9.1? The variable is used. Furthermore, in the case of the call to g(), no possibility exists of j becoming initialized by the call, unlike the call to f() with respect to i.

Print this item

  Rule 12.6 and functions taking/returning Boolean values.
Posted by: zaffanella - 10-02-2012, 09:22 AM - Forum: 6.12 Expressions - Replies (3)

The second part of Rule 12.6 says that:
"Expressions that are effectively Boolean should not be used as operands to operators other than ..."
The list of the allowed operators has been corrected in TC1 to include &&, ||, !, =, ==, != and ?:

What about the function call operator () ?

If a Boolean value (by enforcement or by construction) is used as an argument to a function having a parameter whose type is Boolean (by enforcement), are we violating Rule 12.6? For instance:

Code:
typedef /* Boolean-by-enforcement type */ bool_t;
void foo(bool_t b);

void bar(int32_t a, int32_t b) {
  bool_t b = (a == b);
  foo(b); /* Non-compliant? */
}

A similar conversion problem exists when returning a Boolean value. In this case Rule 12.6 never applies (even though a Boolean value is being "abused") merely because, strictly speaking, the return statement is not an operator. For instance:
Code:
int32_t bar(int32_t a, int32_t b) {
  bool_t b = (a == b);
  return b; /* Compliant? */
}

Are the two examples above matching what was really meant by Rule 12.6 and TC1?

Print this item

  MISRA rule 17.4 violation ?
Posted by: misterb - 26-01-2012, 08:14 AM - Forum: 6.17 Pointers and Arrays - Replies (1)

Hello,

my compiler find in the following code a MISRA violation 17.4 at the last view code lines. Is this correct? If yes, please tell me how to solve the above mentioned code. In my opinion there is no MISRA rule 17.4 violation.

Code:
#define BUF_LEN1     (512u)

/* this violates rule 8.7, but this is intentionaly. It is only a rule 17.4 example */
static uint32_t buf1[BUF_LEN1];
  
static struct TestStruct
{
  uint32_t *buf;
  uint32_t len;
} data1 = {NULL, 0u};

static void InitStruct(uint32_t _len, uint32_t _buf[]);
static void UseStruct(struct TestStruct * data);

int32_t main( void )
{
    
    InitStruct(BUF_LEN1, buf1);
    UseStruct(&data1);

    return 0;
}

static void InitStruct(uint32_t _len, uint32_t _buf[])
{
  data1.len = _len;
  data1.buf = _buf;
}

static void UseStruct(struct TestStruct * data)
{
  uint32_t i;
  
  for (i=0u; ilen; i++)
  {
    /* process data in any way ... */
    /* this code line causes a MISRA 17.4 violation error by the compiler */
    data->buf[i] = 1u;
  }
}

Many thanks in advance and best regards,

Michael

Print this item

  MISRA rule 7.1 Octal constants vs. Linux permissions
Posted by: tharris - 25-01-2012, 01:59 PM - Forum: 6.7 Constants - Replies (2)

MISRA rule 7.1 says don't use octal constants, and gives good reasons.
But code which sets and uses constants which represent Linux file permissions (see, for example, http://www.zzee.com/solutions/linux-perm...ml#numeric), are necessarily octal and code is more readable in that case in octal -- the "native" format for such constants.

Of course an octal number can be written, with the same digits, as hexadecimal, and that would meet the MISRA constraint. But IMHO would not meet the spirit of this rule, which is to avoid writing digits outside the base of the number by mistake. Writing a Linux file permissions constant as hex would mean that by mistake the developer could write a digit between 8 and F, and static analysis (compiler etc) would not catch it because it's legal hex. But illegal file permission digit.

Would people see this as a good place for a deviation from MISRA rule 7.1?

Print this item

  15.1 and "switch(0) case 0:"
Posted by: gs - 10-01-2012, 03:01 PM - Forum: 6.15 Switch Statements - Replies (1)

Hi,
Given the following code:

Code:
...
switch(0)
case 0:
...
does the example presented violate rule #15.1? Syntactically, the "switch(expression)" is followed by a "statement" and not necessarily a "compound statement" as stated in the rule. Therefore, can we correctly presume said code violates said rule?

Print this item

  designated initializers
Posted by: alon - 08-01-2012, 03:11 PM - Forum: General Questions - Replies (1)

This is a C99 feature.

Will Misra- C3 support it ?

Print this item

  Rule 16.8 and 14.7
Posted by: jpmzometa - 06-01-2012, 10:35 PM - Forum: 6.16 Functions - Replies (1)

In rule 16.8 is stated
All exit paths from a function...
whereas rule 14.7 states
A function shall have a single point of exit...

Is there a difference between "exit path" and "point of exit"? If not, should rule 16.8 be interpreted as beginning with "The single point of exit from a function..."?

Regards,

Print this item

  Rule 3-9-1
Posted by: pmhill - 30-12-2011, 08:19 PM - Forum: 6.3 Basic concepts (C++) - Replies (1)

The rule states that the types for a function declaration and definition must be token-for-token identical. How literally should this rule be taken. I have two cases where this rule seems to conflict with normal or good practice.

1. In a function definition, a 'const' qualifier is often included for parameters passed by value as a promise that the implementation will not modify these parameters. This qualifier cannot be included in the declaration. For example:

template
T low_bits_mask(unsigned n);

template
T low_bits_mask(const unsigned n) {
return ~((~static_cast(0))

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,309
» Latest member: 1fuhd
» Forum threads: 1,066
» Forum posts: 2,933

Full Statistics

Online Users
There are currently 44 online users.
» 0 Member(s) | 41 Guest(s)
Bing, Google, UptimeRobot

Latest Threads
13.2 Was TC2 correctly ap...
Forum: 8.13 Side effects
Last Post: misra-c
08-10-2026, 12:47 PM
» Replies: 1
» Views: 625
20.12 Does the stringific...
Forum: 8.20 Preprocessing directives
Last Post: misra-c
08-10-2026, 12:40 PM
» Replies: 1
» Views: 554
13.3 Should side effects ...
Forum: 8.13 Side effects
Last Post: misra-c
08-10-2026, 12:37 PM
» Replies: 1
» Views: 428
11.6 pointer to pointer t...
Forum: 8.11 Pointer type conversions
Last Post: misra-c
08-10-2026, 12:21 PM
» Replies: 2
» Views: 1,032
What is the UTLR of -1?
Forum: 8.10 The essential type model
Last Post: misra-c
08-10-2026, 12:15 PM
» Replies: 1
» Views: 597
10.3 Clarify if narrower ...
Forum: 8.10 The essential type model
Last Post: misra-c
08-10-2026, 11:57 AM
» Replies: 1
» Views: 508
It 8.12 intended to be so...
Forum: 8.8 Declarations and defnitions
Last Post: misra-c
08-10-2026, 11:50 AM
» Replies: 1
» Views: 455
Rule 0.1.1 Example f4
Forum: 4.0 Language independent issues
Last Post: cgpzs
07-10-2026, 11:07 AM
» Replies: 3
» Views: 725
Rule 6-2-2 Usage of std::...
Forum: 6.6 Statements (C++)
Last Post: misra cpp
25-09-2026, 05:43 PM
» Replies: 1
» Views: 436
M5-0-4 switch over unscop...
Forum: 6.5 Expressions (C++)
Last Post: misra cpp
25-09-2026, 01:00 PM
» Replies: 3
» Views: 538