473,796 Members | 2,559 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 8718
James Dow Allen wrote, On 14/08/08 08:22:

<snip>
I've time to read very few Usenet groups these days.
Are many as totally devoid of humor as c.l.c?
You say that but you are failing to spot some of the humour.
Did anyone seriously think I was worried about the warning
message? (I *do* use a simple 'grep -v' to remove
one irrelevant gcc warning, but haven't bothered for
the friendly "dangerous" message.)
Some people are concerned about completely clean builds (no warnings at
all) and it was not obvious to me (at least) whether you were or not.

<snip>
Another poster implied that a reason gets() is "dangerous"
is that it will disappear when the pedants take over
libc!
That would be me (unless someone else posted a similar comment) and I
even put a smiley on it just in case you did not realise it was intended
as a humorous comment.
Does anyone think any of us would have trouble
writing our own gets() when it goes missing from libc?
No.
(This would also be a trivial way to get rid of the
"dangerous" message.) In fact, at the risk of encouraging
the mob to Repeat_The_Obvi ous One_More_Time I'll put a
gets implementation in the public domain right now:

/* Not tested :-) */
char *gets(char *s)
{
s = fgets(s, 1000000, stdin);
The behaviour is not the same as gets if the buffer is larger than
1000000 bytes :-)

<snip>
Hmmm. Surprised that the pedants don't add a string length
count to index() to deal with unterminated strings.
:-) :-) :-) :-)
Must resist bait... must resist bait...

<snip>
--
Flash Gordon
The British one not the American Footballer :-)
Aug 14 '08 #101
Default User said:
Richard Heathfield wrote:
>Alas, many Usanians tend not to notice it.

Please try not to use odd abbreviations that are not standard English.
Such as?

--
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 14 '08 #102
Richard Heathfield wrote:
Default User said:
Richard Heathfield wrote:
Alas, many Usanians tend not to notice it.
Please try not to use odd abbreviations that are not standard
English.

Such as?
Well, Usanians. Do you think that is a standard abreviation? If we're
going to harass people about "u" and "ur", then other such crap should
be frowned upon as well. If you absolutely can't bring yourself to use
the standard term "American", then write it out, as in, "many people
from the USA . . . ."


Brian

Aug 14 '08 #103
Flash Gordon <sp**@flash-gordon.me.ukwri tes:
<snip>
>... In fact, at the risk of encouraging
the mob to Repeat_The_Obvi ous One_More_Time I'll put a
gets implementation in the public domain right now:

/* Not tested :-) */
char *gets(char *s)
{
s = fgets(s, 1000000, stdin);

The behaviour is not the same as gets if the buffer is larger than
1000000 bytes :-)
or if INT_MAX < 1000000. fgets(s, INT_MAX, stdin) is probably the
best bet.

--
Ben.
Aug 14 '08 #104
Default User said:
Richard Heathfield wrote:
>Default User said:
Richard Heathfield wrote:

Alas, many Usanians tend not to notice it.

Please try not to use odd abbreviations that are not standard
English.

Such as?

Well, Usanians. Do you think that is a standard abreviation?
It's not an abbreviation. It's a neologism (but it's a strange breed of
neologism, since it's now quite well-established).

Since you're being so picky about language usage, please learn to type
"abbreviati on" consistently. Your current success rate seems to be 50%,
which is a touch low, wouldn't you say?
If we're going to harass people about "u" and "ur",
You can harass them if you like, but I'd rather not, thanks.
then other such crap should
be frowned upon as well. If you absolutely can't bring yourself to use
the standard term "American",
To what standard does the term "American" conform?

then write it out, as in, "many people
from the USA . . . ."
I find "Usanian" more convenient, thanks.

What was your C question?

--
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 14 '08 #105
On 14 Aug 2008 at 20:06, Default User wrote:
If we're going to harass people about "u" and "ur", then other such
crap should be frowned upon as well.
Say, here's a radical suggestion: why not just not harass people at all?

Aug 14 '08 #106
Richard Heathfield wrote:
Default User said:
Richard Heathfield wrote:
Default User said:

Richard Heathfield wrote:

Alas, many Usanians tend not to notice it.

Please try not to use odd abbreviations that are not standard
English.

Such as?
Well, Usanians. Do you think that is a standard abreviation?

It's not an abbreviation. It's a neologism (but it's a strange breed
of neologism, since it's now quite well-established).
I don't believe to be well-established at all. It's also insulting to
many Americans. But you knew that already.
Since you're being so picky about language usage, please learn to
type "abbreviati on" consistently. Your current success rate seems to
be 50%, which is a touch low, wouldn't you say?
Are you seriously going to nitpick about a typo? That's pretty weak.
then other such crap should
be frowned upon as well. If you absolutely can't bring yourself to
use the standard term "American",

To what standard does the term "American" conform?
A tradition of at least a few hundred years. In both the USA and the
UK. That includes every dictionary of the English language. But you
knew that.
then write it out, as in, "many people
from the USA . . . ."

I find "Usanian" more convenient, thanks.
People who write "u" and "ur" find it to be more convenient as well.

You know that at least one person your choice to be offensive. You are
of course free to post as you wish. As am I. We'll have this discussion
(at least my first part) each time. It's up to you how you want to
approach things.

Brian
Aug 14 '08 #107
Default User said:
Richard Heathfield wrote:
>Default User said:
Richard Heathfield wrote:

Default User said:

Richard Heathfield wrote:

Alas, many Usanians tend not to notice it.

Please try not to use odd abbreviations that are not standard
English.

Such as?

Well, Usanians. Do you think that is a standard abreviation?

It's not an abbreviation. It's a neologism (but it's a strange breed
of neologism, since it's now quite well-established).

I don't believe to be well-established at all.
Since you're being so picky about language, perhaps you should examine the
grammar of that sentence more closely.
It's also insulting to many Americans. But you knew that already.
No, it isn't, and therefore no, I didn't. It is merely descriptive, and in
any case it only applies to around 30% of Americans. (It can hardly be
considered insulting to the 700,000,000 or so Americans to whom it doesn't
apply.)
>Since you're being so picky about language usage, please learn to
type "abbreviati on" consistently. Your current success rate seems to
be 50%, which is a touch low, wouldn't you say?

Are you seriously going to nitpick about a typo? That's pretty weak.
Are you seriously going to nitpick about an accurate descriptive term?
That's even weaker.
then other such crap should
be frowned upon as well. If you absolutely can't bring yourself to
use the standard term "American",

To what standard does the term "American" conform?

A tradition of at least a few hundred years.
Traditions are not standards. K&R C is traditional, but ISO C is standard.
In both the USA and the
UK. That includes every dictionary of the English language. But you
knew that.
Dictionaries are descriptive, not prescriptive, and in any case lag behind
neologisms by a number of years.
> then write it out, as in, "many people
from the USA . . . ."

I find "Usanian" more convenient, thanks.

People who write "u" and "ur" find it to be more convenient as well.
Yes. If that's the way they want to write, let them write that way. And
remember, I am under no obligation to read their articles, nor am I
obliged to provide them with help. If you don't like my use of language,
well, neither are you under any obligation to read my articles or provide
me with help.
You know that at least one person your choice to be offensive.
That sentence no verb. If you're going to pick on other people's language
usage, let your own usage be absolutely perfect. Otherwise, live and let
live. The word "Usanian" was coined (not by me) with the intent, not of
offending, but of describing more precisely the citizens of the United
States. If you are so easily offended, what are you doing on Usenet?
You are of course free to post as you wish. As am I.
*Applause* - I see you understand at last.
We'll have this discussion
(at least my first part) each time. It's up to you how you want to
approach things.
With precision.

--
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 14 '08 #108
Richard Heathfield wrote:
Default User said:
I don't believe to be well-established at all.

Since you're being so picky about language, perhaps you should
examine the grammar of that sentence more closely.
Are you claiming that Usanians was a typo? If not, then it is
irrelevant. I will freely admit that I don't proofread as well as I
should. I won't respond to any others you may find.

Are you seriously going to nitpick about a typo? That's pretty weak.

Are you seriously going to nitpick about an accurate descriptive
term? That's even weaker.
It's not accurate, it's not even sensible. USA is a recognized
abbreviation. "Usa" is not a word. To further hang a suffix off it is
ridiculous. It looks silly, and you offend Americans. Whether you want
to admit it or not, the typical term for people from the only nation
with American in its name is "American".
In both the USA and the
UK. That includes every dictionary of the English language. But you
knew that.

Dictionaries are descriptive, not prescriptive, and in any case lag
behind neologisms by a number of years.
That's true, but they're the best we have. It also doesn't make all
neologisms sensible. Further it doesn't address the offensive nature of
some.
If you don't like my use of
language, well, neither are you under any obligation to read my
articles or provide me with help.
I'm also free to complain about your offensive usage.

Brian
Aug 14 '08 #109
"Default User" <de***********@ yahoo.comwrites :
Richard Heathfield wrote:
>Default User said:
Richard Heathfield wrote:
Default User said:
Richard Heathfield wrote:
Alas, many Usanians tend not to notice it.

Please try not to use odd abbreviations that are not standard
English.

Such as?

Well, Usanians. Do you think that is a standard abreviation?

It's not an abbreviation. It's a neologism (but it's a strange breed
of neologism, since it's now quite well-established).

I don't believe to be well-established at all. It's also insulting to
many Americans. But you knew that already.
[...]

Personally, I know of a grand total of one American who's offended by
it.

Speaking as an American myself, I find the term "Usanian" slightly
odd, mildly amusing, easily understandable, quite unambiguous, and
utterly inoffensive.

I can also understand why residents of North and/or South America
outside the USA might be annoyed by the assumption that the term
"American" applies only to residents of the USA. I'm not interested
in debating whether they *should* find it annoying, but I can
certainly see a rationale for it.

I can see no such rationale for being offended by "Usanians".

The problem, I think, is that the USA is one of the very few countries
whose name doesn't refer specifically to its location, but that does
refer to a larger region within which it's located, but without
acknowleding the subset relationship. "Mexico", for example, is
unambiguous. "South Korea" isn't all of Korea, but the name
acknowledges that.

It's not an easy problem to solve. Perhaps you might consider giving
Richard a break for trying to use what I consider to be quite an
elegant solution.

--
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 14 '08 #110

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

Similar topics

101
3396
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
2839
by: b83503104 | last post by:
When are they not consistent?
4
1302
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
18622
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
7467
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
9366
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
3579
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
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9525
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
10452
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...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5440
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...
1
4115
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
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
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.