mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
CPP: Add a test of ExprHasNoEffect.ql with a call to a 'weak' function.
This commit is contained in:
@@ -33,3 +33,5 @@
|
||||
| volatile.c:12:5:12:9 | access to array | This expression has no effect. | volatile.c:12:5:12:9 | access to array | |
|
||||
| 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 |
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
int myNothingFunction()
|
||||
{
|
||||
// does nothing
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __attribute__((__weak__)) myWeakNothingFunction()
|
||||
{
|
||||
// does nothing, but we could be overridden at the linker stage with a non-weak definition
|
||||
// from elsewhere in the program.
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void testWeak() {
|
||||
myNothingFunction(); // BAD
|
||||
myWeakNothingFunction(); // GOOD [FALSE POSITIVE]
|
||||
}
|
||||
Reference in New Issue
Block a user