[C-safe-secure-studygroup] MISRA C:2012 Rules 10.1, 10.5, 10.8 - Compiler GCC, C90

Charls D. Chap chapcharls at gmail.com
Tue Apr 7 12:07:27 BST 2020


Hi,

I am on an automotive project, but I do not have access on codeprover
target (like polyspace)
Do you have any link of a codeprover, static analysis tool like
polyspace? in order to explore the rules on my own?

GCC, C90 (so no use of _Bool)
Q1.
I had this function
math_signf(const val)
{
    return ( (char) ( (0.0f < val) - (0.0f > val) ) ); /* breaks 10.1,
10.5, 10.8 */
}

I am thinking of this, but I guess it still violates 10.5, 10.8

math_sign(const val)
{
    return ( ((char)(0.0f < val)) - ((char)(0.0f > val)) ); /* breaks
10.5, 10.8 */
}

Any help?

Q2.
float a, b, fy;
unsigned char r = (unsigned char) (( a <= fy) && ( b <= fy)); //
breaks 10.5 should not be cast to an inappropriate essential type

any help?


Q3
float x, y, z;
unsigned char ret = (unsigned char) ( ( x * y) <= z); // breaks 10.8
I am trying to assign to ret  a boolean value, but I cast it to
unsigned char, since _Bool is not allowed
so I have the warning that a Boolean shall not be cast to the
different essential type unsigned

Any help?


Regards,
Charls



More information about the C-safe-secure-studygroup mailing list