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

Clive Pygott clivepygott at gmail.com
Wed Jul 1 18:43:14 BST 2020


Hi Charls

You're finished up on the wrong reflector. This is the working group for
the ISO C language committee's safety and security working group -
principally responsible for
ISO_IEC_TS_17961  C secure coding rules.  We aren't directly connected with
MISRA.

I suggest you post your questions either on the MISRA bulletin board
https://www.misra.org.uk/forum/index.php
or find an appropriate forum on   stackoverflow.com

For question 1, something like

          int math_signf(const int val)
                 {if (val < 0) return 1;
                  if (val > 0) return -1;
                  return 0;
                 }

should do the trick - note MISRA doesn't allow implicit int for returns and
parameters

                 Clive Pygott
                 LDRA Inc


On Wed, Jul 1, 2020 at 10:16 AM Charls D. Chap <chapcharls at gmail.com> wrote:

> 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
>
> _______________________________________________
> C-safe-secure-studygroup mailing list
> C-safe-secure-studygroup at lists.trustable.io
>
> https://lists.trustable.io/cgi-bin/mailman/listinfo/c-safe-secure-studygroup
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.trustable.io/pipermail/c-safe-secure-studygroup/attachments/20200701/ae0a80a0/attachment.html>


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