Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A4-7-1: Guard using "." operator getting ignored #600

Open
nbusser opened this issue Jun 1, 2024 · 0 comments
Open

A4-7-1: Guard using "." operator getting ignored #600

nbusser opened this issue Jun 1, 2024 · 0 comments
Labels
false positive/false negative An issue related to observed false positives or false negatives. user-report Issue reported by an end user of CodeQL Coding Standards

Comments

@nbusser
Copy link

nbusser commented Jun 1, 2024

Affected rules

  • A4-7-1

Description

Changing a class/struct's member value with an arithmetic expression triggers a A4-7-1 warning, despite using an appropriate type guard (example function false_positive).
I have to workaround it by destructuring my member (example function true_negative).

It seems that the "." operator is badly supported.

Triggered warning is cpp/autosar/integer-expression-lead-to-data-loss.

Example

struct A {
  std::int32_t s32;
}

void false_positive(A a) {
  if (a.s32 > std::numeric_limits<std::int32_t>::min()) {
    // Is supposed to be compliant with A4-7-1, but CodeQL reports a warning
    --a.s32;
  }
}

void true_negative(A a) {
  auto s32 = a.s32;
  if (s32 > std::numeric_limits<std::int32_t>::min()) {
    // Compliant with A4-7-1
    --s32;
  }
  a.s32 = s32;
}
@nbusser nbusser added the false positive/false negative An issue related to observed false positives or false negatives. label Jun 1, 2024
@nbusser nbusser changed the title A4-7-1: Guard using "." operator getting ignored A4-7-1: Guard using "." operator getting ignored Jun 1, 2024
@nbusser nbusser changed the title A4-7-1: Guard using "." operator getting ignored **A4-7-1**: Guard using "." operator getting ignored Jun 1, 2024
@nbusser nbusser changed the title **A4-7-1**: Guard using "." operator getting ignored **A4-7-1**: Guard using "." operator getting ignored Jun 1, 2024
@nbusser nbusser changed the title **A4-7-1**: Guard using "." operator getting ignored A4-7-1: Guard using "." operator getting ignored Jun 1, 2024
@lcartey lcartey added the user-report Issue reported by an end user of CodeQL Coding Standards label Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false positive/false negative An issue related to observed false positives or false negatives. user-report Issue reported by an end user of CodeQL Coding Standards
Projects
Development

No branches or pull requests

2 participants