False positive candidate Rule 10.3 for float array zero-initialization

Hello,
Polyspace is raising the 10.3 MISRA violation for array initializations like the one below:
float data[3*3] = {0}
My question: is this the intended behavior of Polyspace? Shouldn't this type of zero-initialization be allowed?
My impression is that the MISRA 2012 standard allows this by exception. Other static analyzers do not raise a warning. Empty array-initialization makes the warning go away, so we may just do that.
Thanks.

 채택된 답변

Anirban
Anirban 2022년 8월 4일
편집: Anirban 2022년 8월 4일

0 개 추천

The problem is not because of the array initialization. Indeed, as you say, MISRA C:2012 standard allows an exception of rule 10.3 for aggregate initializations with {0}.
The violation is shown because you are assigning 0 to a float variable (the two have different essential types, see here for essential types). But the MISRA exception for {0} covers aggregates of all data types. So, this is indeed a false positive (and will be fixed in a future release).

댓글 수: 3

David Sosa
David Sosa 2022년 8월 4일
편집: David Sosa 2022년 8월 4일
It seems like:
float data[3*3] = {0};
should be accepted by exception and your answer would violate rule 9.2?
https://forum.misra.org.uk/thread-1357.html
Thanks for pointing to the discussion. Using 0.0f would remove the Polyspace violation, but not address the intention behind the MISRA exception. This is indeed a false positive and will be fixed in a future release.
I edited the answer above to correct this.
Great! Thanks for you reply.
Cheers.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품

릴리스

R2021b

질문:

2022년 8월 4일

댓글:

2022년 8월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by