This (simplest-example) program is set up so main() calls the makeKey() function and fails to check the return value ...Which demonstrates why, when programming, especially security critical code [I'm looking at you Sony], it is important to check your return values.
[demo.c]
int makeKey (void) { /* returns 0/false if there is an error */
/* //! todo - just return an error for now [fred@sony] */
return 0;
}
int main() {
makeKey(); /* make a new key for the crypto */
return 0; /* return 0=success */
}
I want my compiler (gcc version 12.2.0) to "complain" with a warning/error message such as: "return value not used"
It doesn't seem to matter what switches I add to gcc, it seems happy to ignore this easily-detected mistake ...After reading maaany articles, I've got this far:
gcc -Werror -Wall -Wextra -Wunused-result --warn-unused-result -pedantic-errors -ansi -std=c99 demo.c
...But still no luck!
I have discovered that I can make each function "opt-in" to this sanity/security check with:
int makeKey (void) __attribute__ ((warn_unused_result)) { // returns 0 if there is an error
But I want the security to be enabled by default (with an attribute that allows you to "opt-out", eg. printf())
- Is this even possible with a standard install of
gcc v12? - If so, what command line switch am I missing?