Skip to content

Commit 3a092fa

Browse files
authored
Merge pull request #865 from p-snft/large-parameter-const-reference
Fix reccomendation for LargeParameter (C++)
2 parents e195ac9 + 45a995b commit 3a092fa

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

cpp/ql/src/Critical/LargeParameter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ int doFoo(Names n) { //wrong: n is passed by value (meaning the entire structure
88
...
99
}
1010

11-
int doBar(Names &n) { //better, only a reference is passed
11+
int doBar(const Names &n) { //better, only a reference is passed
1212
...
1313
}

cpp/ql/src/Critical/LargeParameter.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @name Large object passed by value
3-
* @description An object larger than 64 bytes is passed by value to a function. Passing large objects by value unnecessarily use up scarce stack space, increase the cost of calling a function and can be a security risk. Use a pointer to the object instead.
3+
* @description An object larger than 64 bytes is passed by value to a function. Passing large objects by value unnecessarily use up scarce stack space, increase the cost of calling a function and can be a security risk. Use a const pointer to the object instead.
44
* @kind problem
55
* @problem.severity warning
66
* @precision high
@@ -20,5 +20,5 @@ where f.getAParameter() = p
2020
and not t.getUnderlyingType() instanceof ArrayType
2121
and not f instanceof CopyAssignmentOperator
2222
select
23-
p, "This parameter of type $@ is " + size.toString() + " bytes - consider passing a pointer/reference instead.",
23+
p, "This parameter of type $@ is " + size.toString() + " bytes - consider passing a const pointer/reference instead.",
2424
t, t.toString()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| test.cpp:16:13:16:14 | _t | This parameter of type $@ is 4096 bytes - consider passing a pointer/reference instead. | test.cpp:6:8:6:20 | myLargeStruct | myLargeStruct |
2-
| test.cpp:24:44:24:48 | mtc_t | This parameter of type $@ is 4096 bytes - consider passing a pointer/reference instead. | test.cpp:11:7:11:21 | myTemplateClass<myLargeStruct> | myTemplateClass<myLargeStruct> |
3-
| test.cpp:28:49:28:49 | b | This parameter of type $@ is 4096 bytes - consider passing a pointer/reference instead. | test.cpp:6:8:6:20 | myLargeStruct | myLargeStruct |
1+
| test.cpp:16:13:16:14 | _t | This parameter of type $@ is 4096 bytes - consider passing a const pointer/reference instead. | test.cpp:6:8:6:20 | myLargeStruct | myLargeStruct |
2+
| test.cpp:24:44:24:48 | mtc_t | This parameter of type $@ is 4096 bytes - consider passing a const pointer/reference instead. | test.cpp:11:7:11:21 | myTemplateClass<myLargeStruct> | myTemplateClass<myLargeStruct> |
3+
| test.cpp:28:49:28:49 | b | This parameter of type $@ is 4096 bytes - consider passing a const pointer/reference instead. | test.cpp:6:8:6:20 | myLargeStruct | myLargeStruct |

0 commit comments

Comments
 (0)