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

M6-5-3: Triggered when loop counter is passed as const ref #755

Closed
nbusser-sr opened this issue Oct 18, 2024 · 2 comments · Fixed by #773
Closed

M6-5-3: Triggered when loop counter is passed as const ref #755

nbusser-sr opened this issue Oct 18, 2024 · 2 comments · Fixed by #773
Labels
Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Medium Standard-AUTOSAR user-report Issue reported by an end user of CodeQL Coding Standards

Comments

@nbusser-sr
Copy link

nbusser-sr commented Oct 18, 2024

Affected rules

  • M6-5-3: cpp/autosar/loop-counter-modified-within-statement

Rule 6–5–3 (Required)
The loop-counter shall not be modified within condition

or statement.

Description

When passing a loop counter to a function as const ref, M6-5-3 is triggered.

NB: It is also triggered when passed as a mutable ref, but the function never uses the ref. This is less problematic since you should not give a mutable ref argument which is never modified.

Example

std::size_t const_ref(const std::size_t& iRef) {
    return iRef;
}
std::size_t ref(const std::size_t& iRef) {
    return iRef;
}
std::size_t copy(const std::size_t iRef) {
    return iRef;
}

for (std::size_t i{0}; i < 5; ++i) {
  const_ref(i); // Triggers M6-5-3
  ref(i);  // Triggers M6-5-3
  copy(i); // Ok
}
@nbusser-sr nbusser-sr added the false positive/false negative An issue related to observed false positives or false negatives. label Oct 18, 2024
@lcartey lcartey added the user-report Issue reported by an end user of CodeQL Coding Standards label Oct 18, 2024
@lcartey
Copy link
Collaborator

lcartey commented Oct 18, 2024

Thanks! This should be relatively straight-forward to fix.

Note for future implementor, we need to modify Loops.qll to change:

loopCounterAccess.isAddressOfAccess()

to

loopCounterAccess.isAddressOfAccessNonConst()

@lcartey lcartey added Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address Impact-Medium labels Oct 18, 2024
@lcartey lcartey moved this from Reported to Triaged in Coding Standards Public Development Board Oct 18, 2024
fjatWbyT added a commit to fjatWbyT/codeql-coding-standards that referenced this issue Oct 22, 2024
@fjatWbyT
Copy link
Contributor

I think this one is fixed now.

@lcartey lcartey closed this as completed Nov 21, 2024
@lcartey lcartey linked a pull request Nov 21, 2024 that will close this issue
28 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Medium Standard-AUTOSAR user-report Issue reported by an end user of CodeQL Coding Standards
Projects
Development

Successfully merging a pull request may close this issue.

4 participants