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



  10.3 "promoted type" of controlling expression
Posted by: grunwald - 27-02-2020, 02:45 PM - Forum: 8.10 The essential type model - Replies (1)

What exactly is meant by Rule 10.3 using "promoted type" in "The conversion of the constant expression in a switch statement’s case label to the promoted type of the controlling expression." ?
Using the promoted type kinds of contradicts the rule title, which is using essential types.

The following examples assume 10.3 uses the standard C type (after integer promotions) for the controlling expression.
Does the promotion also apply to the case labels, or do we keep using the essential type there? Assuming we keep using the essential type for case labels, that leads to some surprising violations:

uint8_t a = 1;
switch (a) { // type promoted to "signed int"
  case 1u:  // 10.3 violation because 1u is essentially unsigned, but the controlling expression is promoted to an essentially signed type?
  case -200: // compliant with 10.3, even though the case is impossible to reach due to the sign mismatch?

Is there a way to write the following switch that is compliant on both 16-bit and 32-bit machines?
uint16_t num = ...;
switch (num >> 1u) { // uint16_t promotes to 'signed int' or 'unsigned int' depending on "sizeof(uint16_t) == sizeof(int)"
  case 1u:   // 10.3 violation where sizeof(int)>2, because the controlling expression is promoted to an essentially signed type?
  case (uint16_t)2u:  // 10.3 violation where sizeof(int)>2, because the controlling expression is promoted to an essentially signed type?
  case 2:  // I guess signed literals work in all cases, thanks to exception 3.

It would make more sense to use the essential type for both controlling expression and labels; or use the standard type for both.

Print this item

  MISRA C:2012 AMD2 and MISRA Compliance:2020 available
Posted by: david ward - 25-02-2020, 07:18 AM - Forum: Announcements - No Replies

MISRA C:2012 Amendment 2 (which brings C11 into scope) and MISRA Compliance:2020 (which becomes mandatory as the framework for compliance with MISRA C and future releases of MISRA coding guidelines) are now available as free downloads from the "Resources" section of this Bulletin Board.

Print this item

  MISRA Compliance:2020
Posted by: david ward - 25-02-2020, 07:16 AM - Forum: MISRA resources - No Replies

Significant work has taken place within the MISRA C and MISRA C++ Working Groups since the initial release of MISRA Compliance in 2016, with one of the outcomes being that all future releases of MISRA Guidelines will mandate the use of MISRA Compliance.

Up to this point, the MISRA Guideline documents have all included content related to the various MISRA compliance activities. This update to MISRA Compliance enhances Section 2.2 (now titled “Framework”) of Chapter 2 (now titled “The software development process”), completing the definition of what must be covered within the software development process when making a claim of MISRA compliance. This is mainly a “house-keeping” exercise, allowing the compliance-related content to be replaced by references to this document, ensuring consistency among the MISRA Guidelines whilst reducing the effort required in their maintenance.

Attached Files
.pdf   MISRA Compliance 2020.pdf (Size: 302.07 KB / Downloads: 24)
Print this item

  MISRA C:2012 Amendment 2
Posted by: david ward - 25-02-2020, 07:14 AM - Forum: MISRA resources - No Replies

An updated edition of the C Standard, commonly referred to as “C11”, was released just as MISRA C:2012 was being prepared for publication, meaning it arrived too late for the MISRA C Working Group to take it into consideration.

As the adoption of C11 has become more widespread, the MISRA C Working Group have decided that it is now time to address this new edition of the C Standard, support for which will be implemented by means of a series of amendments to MISRA C:2012. This document amends MISRA C:2012 as required to introduce support for ISO/IEC 9899:2011. Subsequent amendments will be used to introduce specific guidance for the features introduced by ISO/IEC 9899:2011.

In the three years since its publication, the additional guidance provided by MISRA Compliance has been increasingly adopted. The MISRA C Working Group have decided that now is the time to upgrade this guidance from optional to be an integral part of the MISRA C lifecycle. Therefore, this document amends MISRA C:2012 to do that.

Attached Files
.pdf   MISRA C 2012 AMD2.pdf (Size: 455.86 KB / Downloads: 22)
Print this item

  Rule 10.6 An expression shall not be assigned to a wider type
Posted by: LordMordac - 27-01-2020, 11:47 PM - Forum: 8.10 The essential type model - Replies (1)

The full rule title is:

Quote:The value of a composite expression shall not be assigned to an object with a wider essential type

I am having a lively debate with my scanner vendor about the quality of their scans. The following example code is generating the commented violation:
static inline uint32_t bit32 (uint32_t pos)
static const uint32_t mask = 31U;
static const uint32_t one = 1U;

// Event misra_c_2012_rule_10_6_violation: Assigning composite expression "1U

Print this item

  Signal naming convention in MISRA guidelines
Posted by: ikostas_arrival - 21-01-2020, 09:31 AM - Forum: MISRA AC SLSF discussions - No Replies


That is my first message on this bulletin, so I am not sure whether this is the right place for my question. If not please direct me to the right thread.

I work in the automotive sector and more specifically in safety critical automotive control design with Simulink etc. So far in my team, we haven't started using an established signal name convention in Simulink that complies with a standard like MISRA. My question is, do you know if there is any of the MISRA documents that provides signal name convention for automotive systems?

In Autosar there is such a keyword list as you can see in the end of this document https://www.autosar.org/fileadmin/user_u...deling.pdf

For example if I want to name a signal with the name vehicle longitudinal velocity. Should it be vhllongvel or vehlngvl or vehllongvel etc. You get the picture.

thanks in advance,


Print this item

  Rule 0-1-6 Variables being given values that are never used.
Posted by: LordMordac - 17-01-2020, 05:34 PM - Forum: 6.0 Language independent issues (C++) - Replies (3)

The actual rule is:

Quote:A project shall not contain instances of non-volatile variables being given values that are never subsequently used.
There has been a lot of discussion as to what that sentence actually means. One camp believes that this rule applies to DU dataflow anomalies only, and the other believes that it applies to DU and DD dataflow anomalies.

For example the following code contains a DD dataflow anomaly, but not a DU dataflow anomaly. Is it a Rule 0-1-6 violation?
int32_t foobar (int32_t const value)
    int32_t returnValue = value;
    if (value < 0)
        returnValue = 0;
    return returnValue;

This debate is influencing discussions on the merits of variable initialization.

Print this item

  MISRA C:2012 Rule 20.5 applicable for inactive code ?
Posted by: Girish - 06-01-2020, 01:43 PM - Forum: 8.20 Preprocessing directives - No Replies


MISRA C:2012 Rule 20.5 - #undef should not be used.

For the following code snippet, #undef is seen at line 5 and 8.
As Rule 20.5 complains for use of #undef, please let us know whether code at line 8, which is inactive code due to #else is Non-compliant or not according MISRA C:2012 Rule 20.5 ?

1. #define FLAG 100
3. #ifdef FLAG
4. #define L 0
5. #undef L
6. #else
7. #define X 0
8. #undef X
9. #endif


Print this item

  Rule M10.1.1
Posted by: phdenis - 05-12-2019, 10:13 PM - Forum: 6.10 Arithmetic Type Conversions - Replies (1)


I've a problem when using the memset function, the error M10.1.1 is raised.
Error raised by the MISRA Tool used (RTRT):
line 12 row 30: Rule M10.1.1
Error: Implicit conversion of an integer expression to a different signedness is not allowed

Regarding the memset prototype,
void *memset (void *s, int c, size_t n);

The content of the test.h file is given see below:

#ifndef __TEST_H__
#define __TEST_H__

#define CST_UZERO   0U
#define CST_STRIPV4 16U /* IP: AAA.BBB.CCC.DDD */

typedef signed char SINT8_T;

void MyFunc(void);

#endif /* __TEST_H__ */

The content of the test.c file is given see below:
#include "test.h"

void MyFunc(void)
    /* Local Variable(s) */
    STRIPV4_T NtpAddr1;
    /* Init */
    (void) memset(&NtpAddr1, CST_UZERO, CST_STRIPV4);

Print this item

  MISRA 25th Anniversary
Posted by: david ward - 28-11-2019, 12:25 PM - Forum: Announcements - No Replies

The MISRA consortium, a world-leading collaboration between manufacturers, component suppliers and engineering consultancies, is celebrating 25 years since the landmark publication of Development Guidelines for Vehicle Based Software.

The guidelines, and the revisions and amendments that have followed, and the broader portfolio of MISRA documents published since then have underpinned significant improvements in vehicular software safety; and the success has seen the principles adopted by many other industries.

The MISRA consortium was conceived in the early 1990s as a project in the UK government’s “SafeIT” programme to develop guidelines for embedded software in road vehicle electronic systems. Membership now consists of members from other industries in the safety-related embedded systems world, alongside automotive companies.

The consortium started with eight core members in the funded project, and now consists of a board of ten in voluntary roles.

Landmark publications include the first edition of MISRA C in 1998, MISRA C:2004, guidelines for safety analysis in 2007, MISRA C++ :2008, MISRA C:2012 and guidelines for safety arguments in 2019.

In the late 1980s, the automotive industry had to adapt to more complex systems of embedded electronics in road vehicles. Starting with the publication of our first guidelines in 1994, MISRA has been at the forefront of making sure our safety standards have developed hand-in-hand with the technological breakthroughs in the industry.

Outside of the automotive sector, the MISRA guidelines have supported the development of renowned technological projects. The Joint Strike Fighter (JSF) project C++ Coding Standard and NASA Jet Propulsion Laboratory C Coding Standards, as used on the Mars Rover missions, are both based on MISRA guidelines.

A full press release is available at the main MISRA website at https://www.misra.org.uk/News/tabid/59/Default.aspx along with an infographic at https://www.misra.org.uk/MISRAHome/MISRA...fault.aspx

Print this item

Search Forums

(Advanced Search)

Forum Statistics
» Members: 5,681
» Latest member: DelayShot
» Forum threads: 880
» Forum posts: 2,427

Full Statistics

Online Users
There are currently 76 online users.
» 0 Member(s) | 74 Guest(s)
Bing, Google

Latest Threads
MISRA C++ new version
Forum: C++ Announcements
Last Post: david ward
30-11-2021, 03:53 PM
» Replies: 7
» Views: 10,932
CWE Coverage by MISRA
Forum: General Questions
Last Post: susanne.goldammer
30-11-2021, 12:23 PM
» Replies: 0
» Views: 24
Rule8.9 applicability to ...
Forum: 8.8 Declarations and defnitions
Last Post: misra-c
27-11-2021, 11:10 AM
» Replies: 1
» Views: 229
Rule 14.3 and preprocesso...
Forum: 8.14 Control statement expressions
Last Post: misra-c
27-11-2021, 11:00 AM
» Replies: 1
» Views: 151
Rule 17.4 and main
Forum: 8.17 Functions
Last Post: misra-c
27-11-2021, 09:58 AM
» Replies: 1
» Views: 166
2.2 Dead code, 'operation...
Forum: 8.2 Unused code
Last Post: misra-c
27-11-2021, 09:18 AM
» Replies: 1
» Views: 170
for loop iterator being c...
Forum: 8.10 The essential type model
Last Post: misra-c
27-11-2021, 09:10 AM
» Replies: 1
» Views: 184
5-2-12 - Does the rule ap...
Forum: 6.5 Expressions (C++)
Last Post: DavidFriberg
24-11-2021, 03:23 PM
» Replies: 0
» Views: 67
6-5-2 and 6-5-4 on while ...
Forum: 6.6 Statements (C++)
Last Post: cgpzs
18-11-2021, 12:09 PM
» Replies: 4
» Views: 244
A3-1-5 - Rationale and ex...
Forum: AUTOSAR C++:2014 rules
Last Post: cgpzs
15-11-2021, 08:45 AM
» Replies: 2
» Views: 191