Thanks to visit codestin.com
Credit goes to github.com

Skip to content

M5-0-12: Incorrect alerts on assignments of valid numerical values #541

Open
@rvermeulen

Description

@rvermeulen

Affected rules

  • M5-0-12

Description

This query reports false positives where an explicitly signed or unsigned char is implicilty converted to an explicitly unsigned or signed char.

This can occur when converting a value which is typed as signed/unsigned char. It can also occur in the expansion of a template parameter, as in this case integer literals will be fully converted to the desired type, which also causes false positives.

In addition, this query is currently only detecting assignments to variables. It should be expanded to detect implicit conversions from char to signed char or unsigned char - for example, in function call arguments.

Example

The following is compliant per example in the standard, however is still seen as a contravention.

void test() {
  unsigned char x = 10; // COMPLIANT
  unsigned char y = x; // COMPLIANT[FALSE_POSITIVE]
  // ...and similar for signed chars
}


template <typename T, T value>
class C1 {
  public:
    C1() : m_value(value) {} // COMPLIANT[FALSE_POSITIVE]
  private:
    T m_value;
};

void fp_test() {
  C1<std::uint8_t, 10> l1; 
  C1<std::uint8_t, 10U> l2;
}

template <typename T, T value>
class C2 {
  public:
    C2() : m_value(value) {} // NON_COMPLIANT
  private:
    T m_value;
};

void fp_test() {
  C2<std::uint8_t, 'A'> l1; 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty-LowA false positive or false negative report which is expected to take <1 day effort to addressImpact-MediumStandard-AUTOSARfalse positive/false negativeAn issue related to observed false positives or false negatives.

    Type

    No type

    Projects

    Status

    Triaged

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions