Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void Q_onAssert() __attribute__ ((noreturn));
- #define Q_ASSERT(test_) ((test_) ? (void)0 : Q_onAssert() )
- void Q_onAssert() {
- abort();
- }
- typedef void (*VoidFunc)(void);
- void sayHello()
- {
- printf("Hello World\n");
- }
- static VoidFunc getEventHandler()
- {
- return sayHello;
- }
- void indirectHello()
- {
- VoidFunc handler = getEventHandler();
- Q_ASSERT(handler != NULL);
- handler();
- }
- int main()
- {
- indirectHello();
- return 0;
- }
- $ gcc temp.c; ./a.out
- Hello World
- $ cppcheck-1.90/cppcheck --enable=all temp.c
- Checking temp.c ...
- temp.c:28:5: warning: Either the condition 'handler!=NULL' is redundant or there is possible null pointer dereference: handler. [nullPointerRedundantCheck]
- handler();
- ^
- temp.c:27:5: note: Assuming that condition 'handler!=NULL' is not redundant
- Q_ASSERT(handler != NULL);
- ^
- temp.c:26:39: note: Assignment 'handler=getEventHandler()', assigned value is 0
- VoidFunc handler = getEventHandler();
- ^
- temp.c:28:5: note: Null pointer dereference
- handler();
- ^
- temp.c:14:0: style: The function 'sayHello' is never used. [unusedFunction]
- ^
- nofile:0:0: information: Cppcheck cannot find all the include files (use --check-config for details) [missingIncludeSystem]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement