Reputation: 8968
I know you quickly clicked this expecting to answer NEVER USE GETS!
but I have a valid reason. I am learning about buffer overflows and need to purposely develop vulnerable software.
So, as the title states, how do I ignore the warnings so the compilation succeeds? I have tried:
gcc bo.c -o bo -Wall
... to no avail.
Thanks for any help.
Upvotes: 0
Views: 7302
Reputation: 11
use fgets
instead of gets
Example:
fgets (foo, sizeof(foo), stdin);
Upvotes: 1
Reputation: 9093
This code:
#include <stdio.h>
int main() {
char foo[10];
gets( foo );
return 0;
}
produces the following output when compiled:
bo.c: In function 'main':
bo.c:4:2: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
gets( foo );
^
/tmp/cclk8TkP.o: In function `main':
bo.c:(.text+0x10): warning: the `gets' function is dangerous and should not be used.
The first warning is from the compiler, and we can see what flag to use to suppress it: -Wno-deprecated-declarations
.
This leaves the second warning, which is from the linker. As far as I can tell there is no way to suppress that warning easily (see here and here). However it should not be a problem, since it is a warning, not an error; the executable gets created.
Upvotes: 3