`A8-5-2`: Reports a violation even for correctly initialized variables as per the rule

Open
#645 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
devtools

Research direction

Start with the CodeQL query implementing rule A8-5-2 and reproduce the reported C++ example. Trace the heuristic that inspects whitespace around initialization, then verify that correctly brace-initialized variables such as a, ret, and bbb are no longer reported while actual violations remain detected.

Written by the indexing model from the issue text.

Description

Difficulty-Low false positive/false negative Impact-Medium Standard-AUTOSAR user-report
Affected rules
  • A8-5-2
Description

This rule reports violation for the following code (which is correct as per the rule).

Example
void example_function() {
  const int32_t a {array[i]};
  int32_t ret {0};
  myclass01 bbb {6};
}

The reason seems to be the limitation mentioned in the query that CodeQL doesn't store this syntactic information about the form of initialization in the database. The heuristic implemented in the query to check for the violation doesn't work for the above code snippet because of the presence of a whitespace between the variable name and the initialization.

Dominant language
CodeQL
Stars
227
Forks
82
Avg merge
6d 7h
Merged PRs (30d)
9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from github/codeql-coding-standards

All issues in github/codeql-coding-standards

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.