Skip to content

Commit 59ff051

Browse files
authored
Merge pull request #842 from github/lcartey/fix-returnref-member-var
ReturnRefOrPointerToAutoVar: Exclude global or member variables
2 parents f4e10dc + 6316375 commit 59ff051

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `M7-5-1`, `RULE-6-8-2` - `FunctionReturnAutomaticVarCondition.ql`, `ReturnReferenceOrPointerToAutomaticLocalVariable.ql`:
2+
- Remove false positives for member and global variables reported under this rule.

cpp/common/src/codingstandards/cpp/rules/returnreferenceorpointertoautomaticlocalvariable/ReturnReferenceOrPointerToAutomaticLocalVariable.qll

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class ReturnReferenceOrPointerToAutomaticLocalVariableSharedQuery exten
1313
Query getQuery() { result instanceof ReturnReferenceOrPointerToAutomaticLocalVariableSharedQuery }
1414

1515
query predicate problems(
16-
ReturnStmt rs, string message, Function f, string f_string, Variable auto, string auto_string
16+
ReturnStmt rs, string message, Function f, string f_string, StackVariable auto, string auto_string
1717
) {
1818
exists(VariableAccess va, string returnType |
1919
not isExcluded(rs, getQuery()) and

cpp/common/test/rules/returnreferenceorpointertoautomaticlocalvariable/test.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,17 @@ void test_templatefunction_return() {
3232
int j = 2;
3333
int k = 3;
3434
t1(j, k);
35+
}
36+
37+
class C1 {
38+
private:
39+
int x;
40+
41+
public:
42+
int test() { return x; } // COMPLIANT - ignore member vars
43+
};
44+
45+
int x;
46+
int test_global() {
47+
return x; // COMPLIANT - ignore global vars
3548
}

0 commit comments

Comments
 (0)