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

ReturnRefOrPointerToAutoVar: Exclude global or member variables #842

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions change_notes/2025-01-09-return-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `M7-5-1`, `RULE-6-8-2` - `FunctionReturnAutomaticVarCondition.ql`, `ReturnReferenceOrPointerToAutomaticLocalVariable.ql`:
- Remove false positives for member and global variables reported under this rule.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class ReturnReferenceOrPointerToAutomaticLocalVariableSharedQuery exten
Query getQuery() { result instanceof ReturnReferenceOrPointerToAutomaticLocalVariableSharedQuery }

query predicate problems(
ReturnStmt rs, string message, Function f, string f_string, Variable auto, string auto_string
ReturnStmt rs, string message, Function f, string f_string, StackVariable auto, string auto_string
) {
exists(VariableAccess va, string returnType |
not isExcluded(rs, getQuery()) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,17 @@ void test_templatefunction_return() {
int j = 2;
int k = 3;
t1(j, k);
}

class C1 {
private:
int x;

public:
int test() { return x; } // COMPLIANT - ignore member vars
};

int x;
int test_global() {
return x; // COMPLIANT - ignore global vars
}
Loading