473,839 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why is it dangerous?

'evening.

I'm not new to C and have been programming in it since I was 8 but
here's a strange problem I've never seen before.

When I compile a program from our C course with a windows compiler
there is no problem but when I try to compile it with a linux compiler
it complains that

a_03.c:(.text+0 x4d): warning: the `gets' function is dangerous
and should not be used.

Is linux more dangerous than windows? Where can I download a
non dangerous gets function? I have never used gets before is
there undefined behavior somewhere?
Here is a trimmed down example program from my assignment that
demonstrates the problem

#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);
}

On windows with TurboC and Lcc no error is printed. On linux with
gcc it says gets is dangerous.

Please advise my instructor says gcc is overly pedantic.
Aug 10 '08
233 8778
Doug Miller said:
In article <WL************ *************** ***@bt.com>, rj*@see.sig.inv alid
wrote:
>>No point. I have no comment to make on your experience, which differs
from mine. It is possible that you are confused by the fact that
Canadians are likely to think of and describe themselves as Canadians
rather than Americans for the same reason that Germans are likely to
think of and describe themselves as Germans rather than Europeans. That
does not mean that Canadians are not Americans, any more than it means
that Germans are not Europeans.

You seem determined to ignore the point here: Canadians *don't* consider
themselves to be "Americans" ,
You seem to be confusing the point, which is that the term "American",
whilst it /does/ apply to Usanians, *also* applies to other people living
in North and South America. Canadians /are/ Americans (whether or not they
consider themselves to be Americans), because they live in America
(specifically, North America) - just as much as Usanians are Americans and
Brazilians are Americans.
your anti-American fantasies to the contrary notwithstanding .
I don't know where you get the idea that I'm anti-American from the fact
that I don't like the idea of discriminating against the 70% of them that
don't live in the USA.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 16 '08 #181
sp******@milmac .com (Doug Miller) writes:
[...]
You seem determined to ignore the point here: Canadians *don't* consider
themselves to be "Americans" , your anti-American fantasies to the contrary
notwithstanding .
I am now determined to ignore the point, whatever it might be.
I invite everyone to join me in ignoring the point. If you must
continue to discuss this, please take it somewhere else.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <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"
Aug 16 '08 #182
In article <WY************ *************** ***@bt.com>, rj*@see.sig.inv alid wrote:
>Doug Miller said:
>In article <WL************ *************** ***@bt.com>, rj*@see.sig.inv alid
wrote:
>>>No point. I have no comment to make on your experience, which differs
from mine. It is possible that you are confused by the fact that
Canadians are likely to think of and describe themselves as Canadians
rather than Americans for the same reason that Germans are likely to
think of and describe themselves as Germans rather than Europeans. That
does not mean that Canadians are not Americans, any more than it means
that Germans are not Europeans.

You seem determined to ignore the point here: Canadians *don't* consider
themselves to be "Americans" ,

You seem to be confusing the point, which is that the term "American",
whilst it /does/ apply to Usanians, *also* applies to other people living
in North and South America.
No, *you're* confusing the point -- which is that while *you* might think
this, *they* don't.
>Canadians /are/ Americans (whether or not they
consider themselves to be Americans), because they live in America
(specificall y, North America) - just as much as Usanians are Americans and
Brazilians are Americans.
Ahh, I see -- what *they* think they are doesn't matter. *You* already know.
Aug 16 '08 #183
Doug Miller said:
In article <WY************ *************** ***@bt.com>, rj*@see.sig.inv alid
wrote:
>>Doug Miller said:
<snip>
>>>
You seem determined to ignore the point here: Canadians *don't*
consider themselves to be "Americans" ,

You seem to be confusing the point, which is that the term "American",
whilst it /does/ apply to Usanians, *also* applies to other people living
in North and South America.

No, *you're* confusing the point
We are not having an argument, merely a contradiction. As such, it is
pointless to continue it.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 16 '08 #184
Doug Miller wrote:
In article <WY************ *************** ***@bt.com>,
rj*@see.sig.inv alid wrote:
>>Doug Miller said:
>>In article <WL************ *************** ***@bt.com>,
rj*@see.sig.inv alid wrote:

No point. I have no comment to make on your experience, which
differs from mine. It is possible that you are confused by the fact
that Canadians are likely to think of and describe themselves as
Canadians rather than Americans for the same reason that Germans are
likely to think of and describe themselves as Germans rather than
Europeans . That does not mean that Canadians are not Americans, any
more than it means that Germans are not Europeans.

You seem determined to ignore the point here: Canadians *don't*
consider themselves to be "Americans" ,

You seem to be confusing the point, which is that the term "American",
whilst it /does/ apply to Usanians, *also* applies to other people
living in North and South America.

No, *you're* confusing the point -- which is that while *you* might
think this, *they* don't.
>>Canadians /are/ Americans (whether or not they
consider themselves to be Americans), because they live in America
(specifically , North America) - just as much as Usanians are Americans
and Brazilians are Americans.

Ahh, I see -- what *they* think they are doesn't matter. *You* already
know.
I tend to note that in literature from before the mid 20th century, the
word "America" and "the Americas" is used quite often to refer to the
entire north and south American landmass, while early travellers seem
to have used the word "American" for all the people of this landmass
simultaneously with other more specific designations.

In any case, calling a Brazilian or a Canadian, or a Cuban "American" is
as "correct" as calling a Japanese, a Mongol, an Indian, a Russian, an
Israeli, and an East Timorese, as an "Asian", even though in day-to-day
life a representative individual of all these countries will not think
of himself as "Asian".

Just as the word "Asian" applies to collectively to all the people of
Asia and not exclusively to the citizens of one or more of it's
constituent countries, the word "American" should also apply to all the
people of north and south America and not exclusively to the citizens
of the USA. I agree that in common usage that it doesn't, but that
doesn't make it "correct".

Personally I don't like the word "Usanian" for a country-specific
designation of the citizens of the USA (the word sounds and feels
awkward), but I can't think of a better word either.

Maybe the time has come to deprecate and mark as obsolescent the whole
notion of continents, and instead just deal with countries? :-)

Aug 16 '08 #185
Richard Heathfield wrote:
Ian Collins said:
>Joachim Schmitz wrote:
>>Antoninus Twink wrote:
On 11 Aug 2008 at 22:17, Richard Heathfield wrote:
Willem said:
>The person driviong that other car would, if you were killed, have
>the very traumatic experience of having caused your death, as
>opposed to just causing you some injuries had you worn your
>seatbelt .
They might also suffer the even more traumatic experience of having
you smash through their windscreen, injuring or even killing them.
Oh come on, has this ever actually happened?
Yes it surely has. It has also happend that passengers not using their
belt injured/killed the (belted) driver in such accidents.
Which is why sensible countries require back seat passengers to wear
seatbelts. How does this relate to C by the way?

It's an analogy to do with the use of gets(), first raised in this thread
by Eric Sosman, in which he suggests that those who use gets() despite its
known dangers are analogous to those who refuse to wear seatbelts. As
such, it's reasonably relevant. Although it is possible to stretch an
analogy too far (which is why "proof by analogy is fraud", as Stroustrup
rightly said), I don't think this has happened yet in the current case.
Ah. This thread had reached the point where it required interpretation!

Given the context, the requirement to wear seatbelts in the back is
quite a good one.

--
Ian Collins.
Aug 16 '08 #186
On 16 Aug 2008 at 20:39, Ian Collins wrote:
Given the context, the requirement to wear seatbelts in the back is
quite a good one.
No, it is an outrageous affront to personal freedom.

I wear a seatbelt whenever I am in a car. I am not an idiot. But who in
the hell does the state think it is to try to legislate and say that I
can't be an idiot if I damn well want to?

Aug 16 '08 #187
On 2008-08-16, Antoninus Twink <no****@nospam. invalidwrote:
On 16 Aug 2008 at 20:39, Ian Collins wrote:
>Given the context, the requirement to wear seatbelts in the back is
quite a good one.

No, it is an outrageous affront to personal freedom.

I wear a seatbelt whenever I am in a car. I am not an idiot. But who in
the hell does the state think it is to try to legislate and say that I
can't be an idiot if I damn well want to?
The wide world of stdin is far more dangerous than the roadways, and
it's much less obvious - especially to somebody new to the field -
what horrible things could happen by feeding gets() a finite buffer.

--
Andrew Poelstra ap*******@wpsof tware.com
To email me, use the above email addresss with .com set to .net
Aug 16 '08 #188
Antoninus Twink wrote:
On 16 Aug 2008 at 20:39, Ian Collins wrote:
>Given the context, the requirement to wear seatbelts in the back is
quite a good one.

No, it is an outrageous affront to personal freedom.

I wear a seatbelt whenever I am in a car. I am not an idiot. But who
in the hell does the state think it is to try to legislate and say
that I can't be an idiot if I damn well want to?
Because one of the "state's" responsibility is to improve the safety of
it's subjects and to inform them of the same?

BTW, this debate about seat-belts is mildly amusing to me, seeing as
here, most cities do not mandate even drivers to wear seat-belts, while
even in the few that do, the very vast majority put them on at traffic
intersections (where a cop or a CCTV might be watching you) and take
them off as soon as they are on their way again.

The accident rate is horrendous, but that has nothing to do with
seat-belts, but with poor driving and completely flouting road
regulations and safety. This is one issue where the "state" might do
well to let it's subjects work it out for themselves and in the
meanwhile accept the minutely larger fraction of causalities that might
result from non-enforcement.

Aug 16 '08 #189
Antoninus Twink wrote:
On 16 Aug 2008 at 20:39, Ian Collins wrote:
>Given the context, the requirement to wear seatbelts in the back is
quite a good one.

No, it is an outrageous affront to personal freedom.

I wear a seatbelt whenever I am in a car. I am not an idiot. But who in
the hell does the state think it is to try to legislate and say that I
can't be an idiot if I damn well want to?
Because the 200lb twat in the back of a 70mph car carries on moving at
70mph when the car comes to an unscheduled stop, not only doing himself
harm (fair enough) but taking out the poor souls in the front on his way
to oblivion.

Same happens to the careful project team when the stubborn nonconformist
idiot team member uses gets.

--
Ian Collins.
Aug 16 '08 #190

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

101
3400
by: Bill Cunningham | last post by:
I read an article in a book about Perl and Common Gateway Interface and it mentioned C. It said that C could damage your computer. I don't know wether it meant the standard or compiler issuses. I was a little upset. Well more upset. I sent Dennis Ritchie and email. I don't know if he'll respond if he gets it. Sometimes he does sometimes not. How can C damage your computer? Bill
1
2846
by: b83503104 | last post by:
When are they not consistent?
4
1303
by: cesark | last post by:
Hi ! I have important doubts about how to handle the security in asp.net vb.net web forms. Somebody can help me? 1. If you have setting ‘validateRequest=true’ in .net framework1.1, What can do you do to improve the security? Because although you have validations on server side you can enter dangerous characters in a text field, with the exception of telephone numbers or similar.
302
18636
by: Lee | last post by:
Hi Whenever I use the gets() function, the gnu c compiler gives a warning that it is dangerous to use gets(). Is this due to the possibility of array overflow? Is it correct that the program flow can be altered by giving some specific calculated inputs to gets()? How could anyone do so once the executable binary have been generated? I have heard many of the security problems and other bugs are due to array overflows.
6
7473
by: Brendan | last post by:
Hi, I'm trying to mimic the IPC/messaging system of an specific OS in a portable way by using GCC's library. The IPC system uses buffered asynchronous messages, where any thread can send a message to any other thread (i.e. to the "threadID") without blocking, and the receiver does any security checks necessary. I'm trying to implement the portable/linux version on top of sockets/datagrams ("SOCK_DGRAM" in the local namespace), and so...
10
9375
by: lovecreatesbea... | last post by:
C stops the conversion from (char **) to (const char **). c-faq.com sec 11.10 has explanation on this point. But, for example, even the conversion from (char *) to (const char *) brings the same dangerous as in the previous conversion. Why the latter simple but dangerous one is allowed in C? $ cat f1.c int main(void) { const char c = 'a';
6
3584
by: Thomas.li | last post by:
Hi, I want to convert CString to LPBYTE like LPBYTE lpByte = (BYTE*)(LPCTSTR)cstring; is it very dangerous to do that?
0
9698
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10914
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7834
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5684
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4071
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.