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

Username
  

Password
  





  Rule 5.6 A ty pedef name shall be a unique identifier
Posted by: xiaoxin - 09-05-2018, 07:36 AM - Forum: 8.5 Identifers - Replies (2)

My doubt about this rule is if they violate rules in different files, as follows.If they violate the rules in the same project.
a.c

Code:
void func ( void )
{
    {
        typedef unsigned char u8_t;
    }
}
b.c
Code:
void func ( void )
{
    typedef unsigned char u8_t;
    â€¦â€¦
    
}
Similarly, there are rules 5.3 : An identifi er declared in an inner scope shall not hide an identifier declared in an outer scope
c.c
Code:
int a =8;
d.c
Code:
void main(){
int a = 9;
}
In other words, whether cross-document considerations are considered。
Looking forward to your reply。

Print this item

  Rule 7-5-3 and storing a reference for later use
Posted by: rrosier - 08-05-2018, 01:12 PM - Forum: 6.7 Declarations (C++) - Replies (4)

Hello,

I am curious if Rule 7-5-3 is only applicable when a reference to a parameter that is passed by const reference is returned from a function, but also if that reference is stored and then used later.

The rationale of the rule states that "It is implementation-defined behaviour whether the reference parameter is a temporary object or a reference to the parameter." and then goes on to say that a temporary object will be destroyed when the function returns and that using an object after its destruction will lead to undefined behaviour.

Considering the following code:

Code:
class TestConstRef
{
public:
  TestConstRef(const T& aT) : mT(aT) {}
  ~TestConstRef() {}

private:
  const T& mT;
};

If I understand the rule correctly, the parameter aT could be a temporary object which will be destroyed when the constructor exits and when the member reference mT is used later, the temporary object that it refers to may (depending on the implementation) no longer exist and that will lead to undefined behaviour.

Could I ask:
  • Is this understanding correct?
  • Is so, why is only returning the reference explicitly covered by the rules, and not storing the reference as in the code snippet above?

Print this item

  Rule 1.3 - Taking address of near auto variable
Posted by: Francois - 30-04-2018, 08:41 AM - Forum: 8.1 A standard C environment - Replies (6)

Hi all,

PC-Lint warn me that i'm using the address of a near auto variable.

My code looks like this:

Code:
/* static var */
static int16_t MySignVar = 0;

StatusType tMyfunc(void)
{
   uint16_t MyUnSignVar = 0U;
   StatusType ReturnValue;
  
   ReturnValue = tSomefunt(Parameter_1, &MyUnSignVar ); /* Note 934: Taking address of near auto variable... [MISRA 2012 Rule 1.3, required]... */
  
   /* MyUnSignVar is always positive */
   MySignVar += (int16_t)MyUnSignVar ;
  
   return (ReturnValue);
}

Could you help me to handle this issue?

Print this item

  MISRA 20.2
Posted by: ankitshah413 - 26-04-2018, 02:18 PM - Forum: 6.20 Standard Libraries - Replies (1)

Hello,

Why the following code is the violation of MISRA 20.2 ?

Code:
#define abs(a)   (((a) < (0)) ? -(a) : (a))

As far as I understand from the topics , 20.2 does not concern with preprocessor identifier then why I get an violation for the same.

Print this item

  Misra Compliant Math Library
Posted by: dejanpan - 23-04-2018, 05:17 AM - Forum: General Questions - Replies (3)

Hi there,
we are looking for a certified (ISO 26262) and possibly Misra compliant Math library. Both C or C++ would do. We would need it to run on both Arm and Intel architectures which for instance eliminates Intel MKL (which is apparently getting certified).

We have looked through the open source implementations, in particular Eigen, Armadillo, or Blaze but all of them throw too many Misra defects.

We would heavily appreciate any suggestions or if none of the libraries are available - what do automotive folks then normally do?


We are looking for the following features in the library:

1. static memory representation:
dense matrices (probably column major for efficient vector representations)
sparse matrices
symmetric matrices
upper/lower triangular matrices
diagonal matrices
block representations

2. basic math operations (in a memory efficient manner):
addition
subtraction
multiplications:
matrix-matrix
matrix-vector
matrix-scalar
vector-vector (inner, outer products)
vector-scalar
transposition
integer powers
able to apply basic scalar math operations on the entire matrix

3. basic solvers:
norms:
froebenius
l2
l1
infinity
matrix inversion
linear system solvers (e.g. Ax = b)

Print this item

  Rule 6-6-5 A function shall have a single point of exit at the end of function.
Posted by: Renan Lavarec - 19-04-2018, 04:24 PM - Forum: 6.6 Statements (C++) - Replies (2)

Hello,

We are interested about id 0000023 but in C++.

We would like to be MISRA compatible.
But forbid multiple return in some case make the code less understandable.
Further more with the use of RAII, it is pretty safe to have multiple return inside a function.
This rule inherited from C where multiple return is highly unsafe is about to evolve in new version of MISRA C++ ?
If not, this is a "Required" rules, could it be added to a "deviation permits" ?


Example:
If we transform this code using "early return pattern" method which is not MISRA on rule 6-6-5.

Code:
int CheckIsOk()
{

if (currentObject == NULL)
{
    return E_ERR_1;
}
if (!IsClassValid(id))
{
    return E_ERR_2;
}

currentObject->test();

return E_OK;
}

into MISRA

Code:
int CheckIsOk()
{
int err = E_OK;
if (err == E_OK && currentObject == NULL)
{
    err = E_ERR_1;
}
if (err == E_OK && !IsClassValid(id))
{
    err = E_ERR_2;
}

currentObject->test(); // Developer miss to add "err == E_OK && "


return err;
}

If you miss to add a test somewhere like for testing "again" currentObject before to use it, you'll get a possible crash....
It increase complexity of code and make it unsecured.
Readability is something very important to get trusty code.

You can also transform it to another form

Code:
int CheckIsOk()
{
    int err = E_OK;
    if (currentObject)
    {
        if (IsClassValid(id))
        {
            currentObject->test();
        }
        else
        {
            err = E_ERR_2;
        }
    }
    else
    {
        err = E_ERR_1;
    }

    // "Difficulties" to add code here
    if( err == E_OK)
    {
        // Do something
    }

    return err;
}

But the readability is less good than "early return pattern", because you "jump" from "if" to "if" and the last part to execute some code is subject to errors (or after any else), if no test are added before the return statement to test the error state.


ps:
In MISRA 2008 document chapter 6-6-5, there is a synthax mistake on fn3, there is missing {}

Print this item

  In Example suit R_05_01_2.c
Posted by: swasti - 17-04-2018, 11:15 AM - Forum: 8.5 Identifers - Replies (1)

In Example suit R_05_01_2.c
Kindly explain why the following code is non-compliant?
int32_t ABC;
int32_t ABC = 0; /* Non-compliant */

Print this item

  How do explicit casts of arguments affect 21.15 (amendment 1)?
Posted by: abgs - 09-04-2018, 07:45 PM - Forum: 8.21 Standard libraries - Replies (1)

When rule 21.15 of MISRA C 2012 Amendment 1 refers to the types that pointer arguments are pointers to, how are explicit casts interpreted? Are the types that they are pointers to considered before or after the cast?

Code:
void f(signed char* a, int* b, size_t n) {
    memcmp(a, a, n); // ok - pointers to same type
    memcmp(b, b, n); // ok - pointers to same type
    memcmp((int*)b, (int*)b, n); // ok - same type and cast has no effect
    memcmp((int*)a, (int*)a, n); // ok? - cast to different pointer type, arguments match before and after but with different matching types
    memcmp(a, b, n); // violation - pointers to different types
    memcmp((int*)a, b, n); // violation? - types only match due to pointer cast
    memcmp((float*)a, (float*)b, n); // violation? - different pointer types cast to third common pointer type
    memcmp((short*)a, a, n); // violation? - original pointer types match before cast
}

Print this item

  CERT C EXP46-C considered Out of Scope by MISRA C:2012 Addendum 3
Posted by: jlerch - 06-04-2018, 09:25 AM - Forum: General Questions - Replies (2)

MISRA C:2012 Addendum 3 defines the coverage classification "Out of Scope" as "Aspects of behaviour are out of scope for C99 and are related to C11." Considering this definition, why is EXP46-C classified "Out of Scope"? It seems, there is no dependency of the rule to C11 at all.

I would actually argue that EXP46-C is covered by MISRA C:2012 essential type model explicitly and strong.

Print this item

  CERT C EXP35-C considered Out of Scope by MISRA C:2012 Addendum 3
Posted by: jlerch - 06-04-2018, 07:45 AM - Forum: General Questions - Replies (1)

MISRA C:2012 Addendum 3 defines the coverage classification "Out of Scope" as "Aspects of behaviour are out of scope for C99 and are related to C11." Considering this definition, why is EXP35-C classified "Out of Scope"? The very first example I see in EXP35-C (section 4.5.1 in CERT C 2016 edition) is a non-compliant example for C99. CERT C actually states that the example would work fine in C11, but fails in C99.

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 382 online users.
» 0 Member(s) | 380 Guest(s)
Bing, Google

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