mirror of
https://github.com/github/codeql.git
synced 2026-05-03 12:45:27 +02:00
CPP: Calls to weak functions should be considered impure.
This commit is contained in:
@@ -275,12 +275,14 @@ class FunctionCall extends Call, @funbindexpr {
|
||||
override predicate mayBeImpure() {
|
||||
this.getChild(_).mayBeImpure() or
|
||||
this.getTarget().mayHaveSideEffects() or
|
||||
isVirtual()
|
||||
isVirtual() or
|
||||
getTarget().getAnAttribute().getName() = "weak"
|
||||
}
|
||||
override predicate mayBeGloballyImpure() {
|
||||
this.getChild(_).mayBeGloballyImpure() or
|
||||
this.getTarget().mayHaveSideEffects() or
|
||||
isVirtual()
|
||||
isVirtual() or
|
||||
getTarget().getAnAttribute().getName() = "weak"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,4 +34,3 @@
|
||||
| volatile.c:16:5:16:7 | * ... | This expression has no effect. | volatile.c:16:5:16:7 | * ... | |
|
||||
| volatile.c:20:5:20:13 | * ... | This expression has no effect. | volatile.c:20:5:20:13 | * ... | |
|
||||
| weak.c:18:2:18:18 | call to myNothingFunction | This expression has no effect (because $@ has no external side effects). | weak.c:2:5:2:21 | myNothingFunction | myNothingFunction |
|
||||
| weak.c:19:2:19:22 | call to myWeakNothingFunction | This expression has no effect (because $@ has no external side effects). | weak.c:9:31:9:51 | myWeakNothingFunction | myWeakNothingFunction |
|
||||
|
||||
@@ -16,5 +16,5 @@ int __attribute__((__weak__)) myWeakNothingFunction()
|
||||
|
||||
void testWeak() {
|
||||
myNothingFunction(); // BAD
|
||||
myWeakNothingFunction(); // GOOD [FALSE POSITIVE]
|
||||
myWeakNothingFunction(); // GOOD
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user