Posts: 15
Threads: 4
Joined: Feb 2016
Reputation:
0
Having given this more thought, I have realised that the example is not relevant to the rule, as casts are explicit conversions by definition.
My understanding is that there are no rules with which the example is non-compliant and the conversion is safe.
<t></t>
Posts: 15
Threads: 4
Joined: Feb 2016
Reputation:
0
This is due to a misinterpretation of Directive 4.6, which doesn't apply to data that are essentially character. In the example, plain char should have been used for the input parameter.
<t></t>
Posts: 15
Threads: 4
Joined: Feb 2016
Reputation:
0
The conversion in the example is actually a constraint violation and an explicit cast would be required. Rule 11.3 would then be satisfied by exception.
<t></t>
Posts: 632
Threads: 18
Joined: Jan 2006
Reputation:
1
This response assumes that uint8_t is defined as "unsigned char".
Section 8.11 of the MISRA-C:2012 guidelines summarizes the implicit conversions that are permitted by the C language. The list of permitted implicit conversions does not include conversions from char* to unsigned char*. Therefore your example violates the constraints of the C language and hence is not compliant with rule 1.1 of the MISRA-C:2012 guidelines.
The example is also not compliant with rule 7.4, which states that "A string literal shall not be assigned to an object unless the object's type is "pointer to const-qualified char"". Assigned includes the implicit conversion that occur on passing an argument to a function.
Posted by and on behalf of the MISRA C Working Group