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

Username
  

Password
  





  Rule 6-3-1: Does it also apply to "case" blocks?
Posted by: cgpzs - 24-08-2023, 12:05 PM - Forum: 6.6 Statements (C++) - Replies (1)

Consider this piece of code:

Code:
enum Foo
{
  a,
  b
};


void foo(Foo f)
{
  switch(f)
  {
    case a:
      std::cout << "a\n";
      break;
    case b:
      std::cout << "b\n";
      break;
  }

}

Is the above compliant with M6-3-1, or does one need to add braces also to the "case" blocks, e.g.:

Code:
case a:
{
  std::cout << "a\n";
  break;
}

Thanks!

Print this item

  MISRA C:2012 Rule 10.8 Clarification
Posted by: uk000032 - 14-08-2023, 01:58 PM - Forum: 8.10 The essential type model - Replies (1)

MISRA C:2012 Rule 10.8 states "The value of a composite expression shall not be cast to a different essential type category or a wider essential type".

One example of a violation given is:

( uint32_t ) ( u16a + u16b ) /* Non-compliant - cast to wider
                              * essential type */

But what about:

( uint32_t ) u16a + ( uint32_t ) u16b  /* Compliant? */

This kind of thing does get flagged by Polyspace 2022b as a violation of Rule 10.8, but am I correct in thinking that casting the variables before the compound operator is applied means that this not in fact a violation?

Print this item

  A8-5-2 + A8-5-3: No usage of auto allowed?
Posted by: chgros - 11-08-2023, 05:36 PM - Forum: AUTOSAR C++:2014 rules - Replies (2)

It appears that it's impossible to use `auto` variables and be compliant with both A8-5-2 (which mandates {} initialization for all variables) and A8-5-3 (which forbids {} initialization for auto variables)
Is that the intention? How is one supposed to use lambdas in that case?

Print this item

  MISRA AC SLSF:2023 released
Posted by: david ward - 09-08-2023, 04:24 PM - Forum: MISRA AC SLSF discussions - No Replies

We are pleased to announce a new version of MISRA AC GMG has been released.

The MISRA Autocode (AC) family of documents deals with the application of language subsets for automatic code generation purposes. This document, MISRA AC SLSF, contains the best practices, captured as a set of design and style guidelines, for the use of The Mathworks® Simulink® and Stateflow® tools for producing models that will be used for simulation and automatic code generation. Updated in June 2023, this second edition is the current version of MISRA AC SLSF. This document supersedes the first edition (published in 2009).

The MISRA webstore provides single-user PDFs and you can purchase a hardcopy via a "print on demand" service at the following link. Please be sure to select the most appropriate “marketplace” for your location to expedite delivery. MISRA AC SLSF:2023 hardcopy

Print this item

  MISRA AC GMG:2023 released
Posted by: david ward - 09-08-2023, 04:23 PM - Forum: MISRA AC GMG discussions - Replies (2)

We are pleased to announce a new version of MISRA AC GMG has been released.

The MISRA Autocode (AC) family of documents deals with the application of language subsets for automatic code generation purposes. This document, MISRA AC GMG, contains the best practices, captured as a set of design and style guidelines, for the use in all graphical modelling environments for producing models that will be used for simulation and automatic code generation. Updated in June 2023, this second edition is the current version of MISRA AC GMG. This document supersedes the first edition (published in 2009).

The MISRA webstore provides single-user PDFs and you can purchase a hardcopy via a "print on demand" service at the following link. Please be sure to select the most appropriate “marketplace” for your location to expedite delivery. MISRA AC GMG:2023 hardcopy

Print this item

  Rule 17.3 when function has definition
Posted by: dunno - 15-06-2023, 02:32 PM - Forum: 8.17 Functions - Replies (1)

I wonder if the code below violates rule 17.3:

void dostuff(int x) {
    // do some stuff..
}

void func(void) {
    dostuff(12);   // <- is 17.3 violated here?
}

Please note that the functions dostuff and func violates rule 8.4 and don't have prototypes.

Question: is 17.3 violated when calling a function that violates rule 8.4?

The rationale for 17.3 also does not apply to my example code as far as I understand:

    If a function is declared implicitly, a C90 compiler will assume
    that the function has a return type of int. Since an implicit 
    function declaration does not provide a prototype, a compiler will
    have no information about the number of function parameters and
    their types. 

Print this item

  21.18 is a safe strncpy function call non-compliant?
Posted by: dunno - 15-06-2023, 01:06 PM - Forum: 8.21 Standard libraries - Replies (2)

I have a philosophical question.


Example code:

void foo() {
    char buf[128];
    strncpy(buf, "hello", 128);
}

The strncpy call does not have any undefined behavior. It will write "hello" in the buffer. Writing 6 bytes in a 128 byte buffer is not undefined behavior.

Does this code then violate rule 21.18? The third argument is larger than the size of the string literal.

Reading the amplification, it seems to me the code in non-compliant.

Reading the rationale, the point of this rule is to avoid buffer overflows. Since there is no buffer overflow does it mean the code is compliant?

Print this item

  MISRA Compliance Matrix
Posted by: vartika.tailor - 08-06-2023, 04:57 PM - Forum: General Questions - Replies (2)

Hi,

Please could you let me know whether I can download a template MISRA 2012 compliance matrix document and the link to the document? 

Kind regards,
Vartika

Print this item

  MISRA C:2012 Example Suite
Posted by: misra-c - 18-05-2023, 05:01 PM - Forum: MISRA resources - No Replies

For info, the MISRA C:2012 Example suite is now available via the MISRA Git Repository

https://gitlab.com/MISRA/MISRA-C/MISRA-C...mple-Suite

At the moment, this is read-only

Print this item

  MISRA C:2023 released
Posted by: david ward - 12-05-2023, 04:29 PM - Forum: Announcements - No Replies

We are pleased to announce the release of MISRA C:2023 (MISRA C Third edition, Second revision). This is a further update which incorporates Amendments 2 – 4 (AMD2, AMD3, AMD4) and Technical Corrigendum 2 (TC2) and incorporates support for C11 and C18 language features.

At the present time this document is available in PDF form, but we will provide an option for purchase of hardcopies in around 4 – 6 weeks’ time using a “print on demand” service.

Further information including FAQs is available on the MISRA website.

The current version history of MISRA C, with the newest first, is as follows

  • MISRA C:2023 (Third Edition, Second Revision) – published 2023, the current version incorporating support for C11 and C18 language features
  • MISRA C:2012 (Third Edition, First Revision) – also known as MISRA C:2019, published 2019, incorporated additional security guidelines
  • MISRA C:2012 (Third Edition) – published 2013, incorporated support for C99 language features, improved strong typing model, analysis keywords
  • MISRA C:2004 (Second Edition) – published 2004, taking into account user feedback and cross-industry applications
  • MISRA C:1998 (First Edition) – published 1998, original guidance emerging from the automotive industry.

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 125 online users.
» 0 Member(s) | 121 Guest(s)
Bing, Facebook, 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: 624
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: 425
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,031
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: 717
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: 434
M5-0-4 switch over unscop...
Forum: 6.5 Expressions (C++)
Last Post: misra cpp
25-09-2026, 01:00 PM
» Replies: 3
» Views: 532