フィルターのクリア

Why does Polyspace report "MISRA C:2012 10.3 and 10.4"

24 ビュー (過去 30 日間)
Cristian PASCALAU
Cristian PASCALAU 2016 年 11 月 28 日
回答済み: Anirban 2022 年 5 月 23 日
In a C project I have a "typedef unsigned char BOOL; and true and false declared as BOOL" and in a function with parameter pointer to a BOOL, I do an assign *Pointer_To_BOOL = TRUE/FALSE and I get "MISRA C:2012 10.3 (Required)   The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category. The expression is assigned to an object with a different essential type category." And also get "MISRA C:2012 10.4 (Required)   Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category. The left operand of the == operator has essentially unsigned type while the right operand has essentially Boolean type." where I check *Poiter_To_BOOL against TRUE/FALSE. Why does Polyspace take an parameter *Pointer_To_BOOL as unsigned char and what can I do to stop getting this warnings (refactor/justify).
Thank you, Cristian PASCALAU
  3 件のコメント
Cristian PASCALAU
Cristian PASCALAU 2016 年 11 月 28 日
TRUE and FALSE are defined as (BOOL)(1U)/ (BOOL)(0U) and I have typedefed unsigned char BOOL.
Lorenz Mende
Lorenz Mende 2017 年 6 月 23 日
Hi Christian, did you already set the -boolean-types with your specific BOOL? If you have done and working with R2016b or lower, than there might be the chance that this is related to a bug and it is fixed in R2017a.
If a update is not possible, you may justify these violations in code -> see chapter "Add Review Comments to Code" in the documentation. It works well, our review process comes too with a justification comment which is detected by doxygen additionally.

サインインしてコメントする。

採用された回答

Anirban
Anirban 2022 年 5 月 23 日
Since R2021a, the checkers 10.x treat macros such as TRUE and FALSE that resolve to 1 and 0 as essentially Boolean. See Polyspace release notes.

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 11 月 28 日
"Why does Polyspace take an parameter *Pointer_To_BOOL as unsigned char"
Because you defined BOOL as unsigned char. You deference a pointer to unsigned char so the result is going to be unsigned char
  4 件のコメント
Cristian PASCALAU
Cristian PASCALAU 2016 年 11 月 29 日
編集済み: Walter Roberson 2017 年 4 月 3 日
But MISRA 10.4 tells me "Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category. The left operand of the == operator has essentially unsigned type while the right operand has essentially Boolean type."
Here is an example of code:
static void DoSomething(BOOL *Pointer_To_BOOL_X, ... )
{
*Pointer_To_BOOL_X = TRUE;
/** here I get warning 10.3 The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category. The expression is assigned to an object with a different essential type category. */
if (*Pointer_To_BOOL_X == TRUE)/* here I get warning 10.4 */
/** do something */
}
Where:
- typedef unsigned char BOOL;
- TRUE (#define TRUE (BOOL)(1u))
- FALSE (#define FALSE (BOOL)(0u))
and function call is: DoSomething(&BOOL_X, ... )
where:
BOOL BOOL_X;
Thank you.
JoseT
JoseT 2017 年 4 月 3 日
Any comments on this issue, please update.

サインインしてコメントする。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by