mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
C++: handle more macros in UseInOwnInitializer
This commit is contained in:
@@ -27,4 +27,7 @@ where init.getDeclaration() = v
|
|||||||
va = mi.getExpr()
|
va = mi.getExpr()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
and not (
|
||||||
|
va.getEnclosingStmt().isInMacroExpansion()
|
||||||
|
)
|
||||||
select va, v.getName() + " is used in its own initializer."
|
select va, v.getName() + " is used in its own initializer."
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
typedef long size_t;
|
typedef long size_t;
|
||||||
|
|
||||||
void test1() {
|
void test1() {
|
||||||
int x = x;
|
int x = x; // BAD
|
||||||
}
|
}
|
||||||
|
|
||||||
void test2() {
|
void test2() {
|
||||||
int x = x = 2;
|
int x = x = 2; // BAD
|
||||||
}
|
}
|
||||||
|
|
||||||
void test3() {
|
void test3() {
|
||||||
int x = 2;
|
int x = 2; // GOOD
|
||||||
}
|
}
|
||||||
|
|
||||||
void test4() {
|
void test4() {
|
||||||
void* x = (void *)&x;
|
void* x = (void *)&x; // GOOD
|
||||||
}
|
}
|
||||||
|
|
||||||
void test5() {
|
void test5() {
|
||||||
size_t x = sizeof(x);
|
size_t x = sizeof(x); // GOOD
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef void *voidptr;
|
typedef void *voidptr;
|
||||||
@@ -28,7 +28,7 @@ voidptr address_of(voidptr &var) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void test6() {
|
void test6() {
|
||||||
voidptr x = address_of(x); // initialize to it's own address
|
voidptr x = address_of(x); // GOOD (implicit conversion to reference)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -38,25 +38,31 @@ struct MyString {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void test7() {
|
void test7() {
|
||||||
MyString ms = {ms.array, {0}}; // initialize to ""
|
MyString ms = {ms.array, {0}}; // GOOD (implicit conversion to pointer)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define uninitialized(x) x
|
#define uninitialized(x) x
|
||||||
|
|
||||||
void test8() {
|
void test8() {
|
||||||
int x = uninitialized(x);
|
int x = uninitialized(x); // GOOD (rval is a macro)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define uninitialized2(x) x = x
|
#define uninitialized2(x) x = x
|
||||||
|
|
||||||
void test9() {
|
void test9() {
|
||||||
int uninitialized2(x);
|
int uninitialized2(x); // GOOD (initializer is a macro)
|
||||||
}
|
}
|
||||||
|
|
||||||
void test10() {
|
void test10() {
|
||||||
int x = x + 1;
|
int x = x + 1; // BAD: x is evaluated on the right hand side
|
||||||
}
|
}
|
||||||
|
|
||||||
void test11() {
|
void test11() {
|
||||||
int x = uninitialized(x) + 1;
|
int x = uninitialized(x) + 1; // BAD: x is evaluated on the right hand side
|
||||||
|
}
|
||||||
|
|
||||||
|
#define self_initialize(t, x) t x = x
|
||||||
|
|
||||||
|
void test12() {
|
||||||
|
self_initialize(int, x); // GOOD (statement is from a macro)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user