mirror of
https://github.com/github/codeql.git
synced 2026-05-01 03:35:13 +02:00
CPP: Add more test cases for LargeParameter.ql.
This commit is contained in:
@@ -1,3 +1,17 @@
|
||||
| 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 |
|
||||
| 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> |
|
||||
| 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 |
|
||||
| test.cpp:78:16:78:16 | a | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
|
||||
| test.cpp:79:16:79:16 | b | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
|
||||
| test.cpp:80:16:80:16 | c | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
|
||||
| test.cpp:81:16:81:16 | d | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
|
||||
| test.cpp:82:16:82:16 | e | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
|
||||
| test.cpp:83:16:83:16 | f | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
|
||||
| test.cpp:84:16:84:16 | g | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
|
||||
| test.cpp:104:16:104:16 | a | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
|
||||
| test.cpp:105:16:105:16 | b | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
|
||||
| test.cpp:106:16:106:16 | c | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
|
||||
| test.cpp:107:16:107:16 | d | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
|
||||
| test.cpp:108:16:108:16 | e | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
|
||||
| test.cpp:109:16:109:16 | f | This parameter of type $@ is 4100 bytes - consider passing a const pointer/reference instead. | test.cpp:58:8:58:19 | MyLargeClass | MyLargeClass |
|
||||
| test.cpp:144:47:144:49 | lhs | This parameter of type $@ is 1028 bytes - consider passing a const pointer/reference instead. | test.cpp:130:7:130:23 | MyArithmeticClass | MyArithmeticClass |
|
||||
|
||||
@@ -52,3 +52,96 @@ struct CustomAssignmentOp {
|
||||
CustomAssignmentOp &operator=(CustomAssignmentOp rhs);
|
||||
char data[4096];
|
||||
};
|
||||
|
||||
// ---
|
||||
|
||||
struct MyLargeClass {
|
||||
public:
|
||||
MyLargeClass();
|
||||
|
||||
void myMethod();
|
||||
void myConstMethod() const;
|
||||
|
||||
int value;
|
||||
char data[4096];
|
||||
};
|
||||
|
||||
void mlc_modify(MyLargeClass &c) {
|
||||
c.value++;
|
||||
}
|
||||
|
||||
int mlc_get(const MyLargeClass &c) {
|
||||
return c.value;
|
||||
}
|
||||
|
||||
void myFunction4(
|
||||
MyLargeClass a, // GOOD: large, but the copy is written to so can't be trivially replaced with a reference [FALSE POSITIVE]
|
||||
MyLargeClass b, // GOOD [FALSE POSITIVE]
|
||||
MyLargeClass c, // GOOD [FALSE POSITIVE]
|
||||
MyLargeClass d, // GOOD [FALSE POSITIVE]
|
||||
MyLargeClass e, // GOOD [FALSE POSITIVE]
|
||||
MyLargeClass f, // GOOD [FALSE POSITIVE]
|
||||
MyLargeClass g // GOOD [FALSE POSITIVE]
|
||||
)
|
||||
{
|
||||
MyLargeClass *mlc_ptr;
|
||||
int *i_ptr;
|
||||
|
||||
a.value++;
|
||||
b.value = 1;
|
||||
c.data[0] += 1;
|
||||
d.myMethod();
|
||||
mlc_modify(e);
|
||||
|
||||
mlc_ptr = &f;
|
||||
mlc_modify(*mlc_ptr);
|
||||
|
||||
i_ptr = &g.value;
|
||||
*(i_ptr)++;
|
||||
}
|
||||
|
||||
void myFunction5(
|
||||
MyLargeClass a, // BAD
|
||||
MyLargeClass b, // BAD
|
||||
MyLargeClass c, // BAD
|
||||
MyLargeClass d, // BAD
|
||||
MyLargeClass e, // BAD
|
||||
MyLargeClass f // BAD
|
||||
)
|
||||
{
|
||||
const MyLargeClass *mlc_ptr;
|
||||
const int *i_ptr;
|
||||
int i;
|
||||
|
||||
i = a.value;
|
||||
i += b.data[0];
|
||||
c.myConstMethod();
|
||||
i += mlc_get(d);
|
||||
|
||||
mlc_ptr = &e;
|
||||
mlc_get(*mlc_ptr);
|
||||
|
||||
i_ptr = &f.value;
|
||||
i += *i_ptr;
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
class MyArithmeticClass {
|
||||
public:
|
||||
MyArithmeticClass(int _value) : value(_value) {};
|
||||
|
||||
MyArithmeticClass &operator+=(const MyArithmeticClass &other) {
|
||||
this->value += other.value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
int value;
|
||||
char data[1024];
|
||||
};
|
||||
|
||||
MyArithmeticClass operator+(MyArithmeticClass lhs, const MyArithmeticClass &rhs) { // GOOD [FALSE POSITIVE]
|
||||
lhs += rhs; // lhs is copied by design
|
||||
return lhs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user