Note: I just realized that your question title seems to be misplaced - The warning you got is from macOS about executing a program which uses gets()
. It has nothing to do with the compilation by using GCC.
:-/ Any way, I let my answer alive for reference.
Just as comment: I googled a bit about what you are looking for, but there seems to be no reliable way to disable this warning when executing the program. One suggested rebuilding /usr/lib/libSystem.B.dylib
without any result or experience if it indeed works, but I personally think this a bit too extreme and even can be harmful. - I do not recommend this technique.
If you really want to create an exploit program, try to rebuild gets()
by a costum-made function and name the function a bit different, like f.e. gets_c()
. This should be a workaround to disable this warning from macOS.
Old answer (regarding GCC itself):
First of all, you seem to be using a C99 or C89/C90-compliant compiler or alternatively compile with std=c99
or std=c89
/std=c90
option, because only compilers conform to standards preceding C11 warn about gets()
being deprecated.
ISO/IEC removed the gets()
function in C11. If you would compile with a C11 or newer standard-compliant compiler, you would get an error about the implicit declaration of gets()
when using it in the code instead:
"error: implicit declaration of function 'gets'
; did you mean 'fgets'
? [-Werror=implicit-function-declaration
]"
If you want to suppress the warning at compilation, use the -Wno-deprecated-declarations
option at compiling to disable the diagnostic for deprecated declarations.
From the GCC online docs:
-Wno-deprecated-declarations
Do not warn about uses of functions, variables, and types marked as deprecated by using the deprecated attribute. (see Function Attributes, see Variable Attributes, see Type Attributes.)
Source: https://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Warning-Options.html
If you want to embed the suppression of the warning in your code use the approach used in David´s deleted answer implementing a suppression for -Wno-deprecated-declarations
by using #pragma
:
char str[256];
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
gets(str);
#pragma GCC diagnostic pop