 |
 |
Disabling compiler warnings
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jul 2004
Status:
Offline
|
|
Hello
I have searched quite a bit (on Google) looking for a way to turn off the warning displayed when I run compiled C programs that use the function "gets()."
I am using 10.3.4 with Xcode.
I simply want to suppress the message "warning: this program uses gets(), which is unsafe" that appears each time the program runs. Can it be done?
Note that I did NOT come here to be told, "you shouldn't do it." I realize why one shouldn't use gets() because of the buffer overflow security implications. I am doing this for my own knowledge.
And, if the information can easily be found on Google, please tell me what query will do so, as I haven't been able to construct one that will easily do it. And yes, I have perused the man page, but the information wasn't completely clear, and nothing I tried would work.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
I don't think gcc has an option for doing this. Shouldn't matter too much anyway. It's just a warning; it won't stop your compile. If it's really getting on your nerves — and you don't care about flaws in the program, which you obviously don't if you want to do this — you can turn off warnings with -w.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Jun 2001
Location: Northwest Ohio
Status:
Offline
|
|
Originally posted by Chuckit:
I don't think gcc has an option for doing this. Shouldn't matter too much anyway. It's just a warning; it won't stop your compile. If it's really getting on your nerves — and you don't care about flaws in the program, which you obviously don't if you want to do this — you can turn off warnings with -w.
I don't think he's talking about compile-time warnings. He's talking about runtime warnings... when you run a compiled program that uses gets(), the computer first gives the warning, then runs the program.
He wants to turn off the warning displayed each time he runs the program (after it's been compiled).
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by Person Man:
I don't think he's talking about compile-time warnings. He's talking about runtime warnings... when you run a compiled program that uses gets(), the computer first gives the warning, then runs the program.
No, I think it's a compile-time warning.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Jun 2001
Location: Northwest Ohio
Status:
Offline
|
|
Originally posted by Angus_D:
No, I think it's a compile-time warning.
Try this:
Enter the following code in your favorite editor:
Code:
#include <stdio.h>
int main(void)
{
char buffer[256];
printf("\nEnter your name and press <return>: ");
gets(buffer);
printf("\nYour name is %s.\n", buffer);
return 0;
}
save it as name.c
Go to the terminal and compile the code: cc name.c
Note that the compiler does not give any warnings at compile time.
Now execute the program by typing ./a.out
The program will print "warning: this program uses gets(), which is unsafe." before the program executes, EACH and EVERY time the program executes.
There doesn't appear to be any way to turn this off.
In fact, if you open a.out with the editor and look through the gibberish for human-readable text, you won't find the text of the warning in there, which leads me to believe that the kernel is responsible for the message, NOT the compiler. 
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
I think it's in libc. It probably has a __constructor__ function that prints the message if gets is used or something like that.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Sep 2002
Status:
Offline
|
|
If that's the case (and if it's runtime, then libc is rather more likely than the kernel), then all the OP needs to do is get hold of the source to libc, and remove the warning. Shouldn't be a problem for anyone who can use gets().
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by Richard Edgar:
If that's the case (and if it's runtime, then libc is rather more likely than the kernel), then all the OP needs to do is get hold of the source to libc, and remove the warning. Shouldn't be a problem for anyone who can use gets().
Yeah, it's in Libc, removing the warning from the source is trivial.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|