How can I avoid invalid warning C6011 due to an abort function calling exit()
c
Solution
In MSVC, defining `__declspec(noreturn)` for `abort_function` should do it. For gcc, `__attribute__ ((noreturn))` does the same.
Problem
I am trying to avoid C6011 warning because an abort function is calling exit(). How can I do that? Here is an example: ``` #include <stdlib.h> void abort_function(); void func( int *p ); int main() { int x; func( &x ); return 0; } void func( int *p ) { if (NULL == p) abort_function(); *p = 5; } void abort_function() { exit(0); } ``` So this leads to the following warning from PREFast: ``` warning C6011: Dereferencing NULL pointer 'p': Lines: 17, 18, 20 ``` Simply replacing `abort_function()` with `exit(0)` eliminates this warning. But I'm actually working with a large codebase, and I didn't want to replace all calls to `abort_function()`. So I was able to eliminate a lot of these warnings by making the function a variadic macro, and temporarily taking out the function definition, like this: ``` #include <stdlib.h> #define abort_function( ... ) exit(0); /*void abort_function();*/ void func( int *p ); int main() { int x; func( &x ); return 0; } void func( int *p ) { if (NULL == p) abort_function(); *p = 5; } #if 0 void abort_function() { exit(0); } #endif ``` This also eliminated the warning, but are there any PREFast options or annotations I could use, to avoid having to modify the code?