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

Username
  

Password
  





  Rule 3.6: Supplied Libraries Compliance Check
Posted by: MichelCampmas - 16-11-2009, 06:21 PM - Forum: 6.3 Documentation - Replies (1)

We are using an ARM development suite where standard libraries are provided with the tool suite. Looking at the MISRA rules, I found quite a few which prohibit using such and such function (atoi, etc...). Which means that implicitly, the other functions can be used.
However, rule 3.6 requires that all libraries (including the ones provided with the compiler) be "subjected to appropriate validation".
Could you expand on what this means in regards to standard libraries? Do we need to require the vendor to certify he is MISRA compliant? If not possible, does this means we have to write our own version, so that we are sure it is compliant?
Thanks
Michel Campmas
Cypress Semiconductor

Print this item

  Is below code is compliant to rule 10.1?
Posted by: Pundlik Oulkar - 11-11-2009, 05:15 AM - Forum: 6.10 Arithmetic Type Conversions - Replies (1)

//Example 1:

struct xyz {
unsigned char bit:1;
}abc={0} ; // Is this assignment to bit-field is compliant to MISRA rule10.1 and Why?

Print this item

  Rule 15.0 - Required or Adviosry?
Posted by: William Forbes - 24-10-2009, 06:32 PM - Forum: 6.15 Switch Statements - Replies (4)

TC1 introduced the concept of rule 15.0.
However it does not explicitly state if this rule is "Required" or "Advisory"
Is rule 15.0 "required" or "advisory"?

Print this item

  Rule 16.9 - Error in code example
Posted by: William Forbes - 24-10-2009, 04:18 PM - Forum: 6.16 Functions - Replies (4)

The code in the normative text of rule 16.9 is:

Code:
if (f)     /* not compliant - gives a constant non-zero value which is
{             the address of f - use either f() or &f */
    /* ... */
}
Maybe it should be:
Code:
if (f)     /* not compliant - gives a constant non-zero value which is
              the address of f - use either f() or &f */
{
    /* ... */
}

Note - the opening brace was inside the comment.
A trivial error but maybe it should get corrected?

Print this item

  14.10 /* no else needed */
Posted by: ABR - 22-10-2009, 01:15 PM - Forum: 6.14 Control Flow - Replies (2)

In rule 14.10 (all if..... else if constructs shall be terminated with an else clause":

is the /* no else needed */ comment on the single if block with no else a suggestion for use in code, where seems useful?

Print this item

  Will there be Model Advisor rules?
Posted by: Matt Cook - 21-10-2009, 01:10 PM - Forum: MISRA AC SLSF discussions - Replies (1)

I am aware that Simulink already has Model Advisor rules for checking against the MAAB guidelines ... as well as MISRA-C, IEC 61508 and DO-178B.

Does anyone know if The Mathworks plan to introduce similar rule checking for this guideline document? (or others)
... and if so, would they be linked to any particular tool license?

Would there be any plan for MISRA to be involved in their formulation? ... or any kind of formal or informal 'approval' process of them?

Print this item

  I question the need of rule 10.6
Posted by: Lundin - 07-10-2009, 09:19 AM - Forum: 6.10 Arithmetic Type Conversions - Replies (8)

This rule seems to be commonly deviated from by most people I have spoken to. I have given it thought, but I still cannot understand how it would lead to more secure programs.

The only argument provided by MISRA for this rule is that “the type of an integer constant is a potential source of confusion”. Yes it is confusing, but only from a theoretical point-of-view, namely when you are determining what implicit type conversions that are done on the integer constant. That is, during a "scratch your head while learning C" session. During actual programming, you don't need to think about this.

I can't come up with one single scenario where leaving out the “U” suffix will lead to bugs or unintended behavior. Can anyone make such an example? If one integer in the operation is signed and the other is unsigned, and they are both of the same size, the "usual arithmetic conversions" will make sure both are unsigned. Consider the following example:

result = -1 - 10;

In this example, the type of -1 is "signed int" and the type of 10 is "int". If "int" is treated as signed by the compiler, there will not be any problems as both operands are then signed.
If "int" is treated as unsigned, then the operand -1 will be converted to unsigned, that is, to the value 65535 (assuming 16-bit system). The result of the expression will then be 655535 - 10 = 65525, which may not be the result the programmer expected. However, this will not lead to a bug! Because we aren't done with that line.

If "result" is of signed type, then the result 65525 will be converted to signed during the assignment, making it -11, which is the expected result.
If "result" is of unsigned type, the code does not make sense. If you try to stuff signed constants into a unsigned variable, no U suffix will save you.

MISRA fails to name a case where the lack of a “U” suffix would cause bugs. Integer constants are by their nature constant, and therefore deterministic. ISO C ensures that they are of the right size and signedness. It all boils down to what type the result is stored inside. If the type of the expression happens to be of different type than the variable, an implicit typecast will be done upon assignment to correct this.

Rule 10.6 also states that the implemented sizes of integer types is a reason why the U suffix should be used. I fail to see how this is relevant to the use of the U suffix. The example says that 40000 will be int or long depending on system... this has nothing to do with signedness at all. The example says that 0x8000 is possible signed in a 32-bit environment... so what? It is still a positive number in 32 bit. And you won't notice the signedness of a hex number until you represent it in a decimal format, and then it is up to you whether you want to display it as signed or unsigned.

Also, integer constants are never subject to the integer promotions, as they are always "int" or "long", so no need to worry about that either.

Further, writing “U” all over the source code is not common practice among programmers. It causes much more confusion than the hidden signedness of integer constants and worst of all, it makes the code harder to read. In addition, the MISRA-C document in itself is filled with examples where MISRA themselves do not even follow this rule. I can easily come up with countless examples, just open a random page and you will likely find it. The rule is simply too rigid and not practical to use in reality.

Though perhaps there exists a case when the lack of this suffix will lead to bugs? If not, I don't see any reasons keeping this rule.

Print this item

  Double casting to bypass 11.4?
Posted by: exoson - 04-09-2009, 10:48 PM - Forum: 6.11 Pointer Type Conversions - Replies (3)

I ran into an issue with a static analysis tool the other day.

In my example:
pool_ptr->list = *((UCHAR **) work_ptr); /*violates MISRA 11.4 */
Both pointers are UCHAR *. The first location in the buffer is being used to hold another pointer.

Adding an intermediate cast to void * clears the warning.
pool_ptr -> tx_list = *((UCHAR **) (void *)work_ptr);

Regardless that this clears the message, I believe it is still a violation of the intent of MISRA 11.4. Do you agree?
-----------------------------------------------------------------------
Scott Nowell
Validated Software Corporation

Print this item

  Combining case and default?
Posted by: exoson - 07-08-2009, 04:21 PM - Forum: 6.15 Switch Statements - Replies (1)

I would be interested in comments on the following simplified fragment.

switch (err) {
case 0:
...
break;

case 1:
case 2:
case 3:
default:
...
break;
}

I am seeing code examples like this where multiple cases are being combined with default. Most compiler will simply optimize this out to a simple test for case 0. The programmers are using this as a way to identify the results they might expect. I think having the other cases in a comment would serve this as well. MISRA C does not seem to mention this.
From a test perspective I feel it is necessary to test all declared cases.
Can anyone offer a comment on this?

Scott
Validated Software

Print this item

  MISRA C++ compliant definition of NULL
Posted by: jorgen_h_karlsson - 05-08-2009, 02:17 PM - Forum: 6.3 Basic concepts (C++) - Replies (1)

According to the rationale of required rule 3-1-1 a header file should not contain or produce definitions of objects or functions.

Does this mean that the following definition of the null-pointer-constant NULL is non-compliant?

Code:
const int NULL = 0; // Compliant with rule 3-1-1?
If so, what is a compliant definition of NULL then?

Best regards,
/J

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 6,171
» Latest member: stephanmuench
» Forum threads: 998
» Forum posts: 2,752

Full Statistics

Online Users
There are currently 285 online users.
» 0 Member(s) | 282 Guest(s)
Applebot, Bing, Google

Latest Threads
Rule 6.2.1: non-inline co...
Forum: 4.6 Basic concepts
Last Post: cgpzs
22-11-2024, 10:11 AM
» Replies: 0
» Views: 36
Rule 0.1.2
Forum: 4.0 Language independent issues
Last Post: stephanmuench
21-11-2024, 01:12 PM
» Replies: 0
» Views: 44
A18-9-4
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
23-10-2024, 12:04 PM
» Replies: 2
» Views: 398
A8-4-5: are partial moves...
Forum: AUTOSAR C++:2014 rules
Last Post: misra cpp
22-10-2024, 02:03 PM
» Replies: 1
» Views: 339
model information blocks ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:27 PM
» Replies: 1
» Views: 4,459
MISRA AL SLSF - Rule 043I
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
22-10-2024, 01:11 PM
» Replies: 1
» Views: 8,875
MISRA AC EC guidelines
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:21 AM
» Replies: 4
» Views: 15,523
News on future releases
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 08:05 AM
» Replies: 1
» Views: 5,707
Signal naming convention ...
Forum: MISRA AC SLSF discussions
Last Post: misra-ac
21-10-2024, 07:57 AM
» Replies: 1
» Views: 7,258
Rule 7.0.2: operator cons...
Forum: 4.7 Standard conversions
Last Post: karos
14-10-2024, 08:52 PM
» Replies: 2
» Views: 448