Re: Why is it dangerous?
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Sat, 09 Aug 2008 20:20:01 -0700
Julian <juli@xxxxxxxxxxxxxx> writes:
[...]
#include <stdio.h>[...]
#include <malloc.h>
void main()
{
char *string;
printf("enter string (max 2000 chars): ");
fflush(stdin);
fflush(stdout);
string = (char *)malloc(2001);
if(!string) exit(1);
gets(string);
printf("you entered: %s\n", string);
free(string);
exit(0);
}
This program, in 16 lines, exhibits at least 6 blatant errors or
gratuitous non-portabilities that have been discussed repeatedly in
this newsgroup: <malloc.h>, "void main()", "fflush(stdin), casting the
result of malloc(), exit(1), and of course the use of gets().
Either this is deliberate, and Julian is a troll, or it's not, and
he's been very poorly taught. In the latter case, Julian, please read
read the comp.lang.c FAQ <http://www.c-faq.com/>, and feel free to
post again if you still have any questions.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- References:
- Why is it dangerous?
- From: Julian
- Why is it dangerous?
- Prev by Date: Re: Variable naming conventions.
- Next by Date: Re: Why is it dangerous?
- Previous by thread: Re: Why is it dangerous?
- Next by thread: Re: Why is it dangerous?
- Index(es):
Relevant Pages
|