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

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

Open
rak3-sh opened this issue Jul 17, 2024 · 3 comments
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 user-report Issue reported by an end user of CodeQL Coding Standards

Comments

@rak3-sh
Copy link
Contributor

rak3-sh commented Jul 17, 2024

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.

@rak3-sh rak3-sh added the false positive/false negative An issue related to observed false positives or false negatives. label Jul 17, 2024
@lcartey lcartey added Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address Impact-Medium user-report Issue reported by an end user of CodeQL Coding Standards labels Jul 17, 2024
@lcartey
Copy link
Collaborator

lcartey commented Jul 17, 2024

Thanks for this report! The good news is that since we originally wrote this query, the C/C++ CodeQL standard library has gained additional information on the type of initialisation in the database (Initialiser::isBraced()), so this should now be straightforward to improve.

@rak3-sh
Copy link
Contributor Author

rak3-sh commented Jul 18, 2024

Thank you for your prompt reply! I just checked isBraced and while it correctly identifies a braced initialization but it is not able to distinguish between the initialization when = is used and when it is not used. E.g. it returns true for both the variables below.

CLASSA a41{};
CLASSA a43 = {};

@lcartey
Copy link
Collaborator

lcartey commented Jul 19, 2024

Ah, you're right. isBraced will improve this query by removing false positives where bracing wasn't used, but won't resolve the case in your report because it is already braced, and we don't have an equivalent concept for whether it was initialized by ={..} vs {..}.

We will at least fix the isBraced issue, and consider whether it's possible to adjust our extractor to include enough information for this specific case.

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 user-report Issue reported by an end user of CodeQL Coding Standards
Projects
Development

No branches or pull requests

2 participants