MISRA C:2012 Rule 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

Description

Rule Definition

The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category.

Rationale

The use of implicit conversions between types can lead to unintended results, including possible loss of value, sign, or precision.

For more information on essential types, see MISRA C:2012 Rule 10.1.

Polyspace Implementation

The checker raises a violation if an expression is assigned to a variable with a narrower essential type or a different essential type category.

The checker does not raise a violation of this rule:

  • If the expression is simply the constant zero.

  • If a signed constant is assigned to an unsigned variable but the signed constant has the same representation as its unsigned equivalent. For instance, the checker does not flag statements such as:

    unsigned int u = 1;

Additional Message in Report

  • The expression is assigned to an object with a different essential type category.

  • The expression is assigned to an object with a narrower essential type.

Troubleshooting

If you expect a rule violation but do not see it, refer to the documentation of Polyspace® Code Prover™ or Polyspace Code Prover Server™.

Check Information

Group: The Essential Type Model
Category: Required
AGC Category: Advisory