473,804 Members | 2,136 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 8725
"Joachim Schmitz" <no*********@sc hmitz-digital.dewrite s:
Keith Thompson wrote:
>"Joachim Schmitz" <no*********@sc hmitz-digital.dewrite s:
>>Antoninus Twink wrote:
[...]
>>>
Utter nonsense.
[...]

Please stop feeding the troll.

Please leave this to my discretion.
I never implied that it isn't up to your discretion.
I merely made a request.

--
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 18 '08 #221
Keith Thompson wrote:
"Joachim Schmitz" <no*********@sc hmitz-digital.dewrite s:
>Keith Thompson wrote:
>>"Joachim Schmitz" <no*********@sc hmitz-digital.dewrite s:
Antoninus Twink wrote:
[...]

Utter nonsense.
[...]

Please stop feeding the troll.

Please leave this to my discretion.

I never implied that it isn't up to your discretion.
I merely made a request.
Sorry, point taken. I seem to be overly thin skinned lately...
Aug 18 '08 #222
In article <ln************ @nuthaus.mib.or g>,
Keith Thompson <ks***@mib.orgw rote:
>"Joachim Schmitz" <no*********@sc hmitz-digital.dewrite s:
>Keith Thompson wrote:
>>"Joachim Schmitz" <no*********@sc hmitz-digital.dewrite s:
Antoninus Twink wrote:
[...]

Utter nonsense.
[...]

Please stop feeding the troll.

Please leave this to my discretion.

I never implied that it isn't up to your discretion.
I merely made a request.
I see what you mean, but it is a fine line you tread.

Like it or not, you (and your cronies) have set yourselves up as
newsgroup cops in CLC - and you enforce the topicality rules with
aplomb. So, when you speak, it carries somewhat more force than when
Joe Newbie speaks. People are expected to follow your directives, just
as they are expected to follow the directives issued by real life cops.

Aug 18 '08 #223
Richard Heathfield <rj*@see.sig.in validwrote:
>
If you'd looked a little closer, you'd have found that C99's usage of the
word "abbreviate d" (which has the same root as "abbreviati on") clearly
disagrees with the way I was taught at school. (See 7.23.3.5(3) for
details.) Thus, this discussion has uncovered a flaw in the Standard! So
it seems it may conceivably have been worthwhile after all. :-)
Are you sure it's a flaw in the standard rather than a flaw in your
schooling? :-)

My dictionary accepts any form of shortening as an abbreviation; an
abbreviation formed from the initial letters of words is either an
/acronym/ (if pronounceable) or an /initialism/ (if not).

What does the OED have to say?
--
Larry Jones

Years from now when I'm successful and happy, ...and he's in
prison... I hope I'm not too mature to gloat. -- Calvin
Aug 18 '08 #224
In article <-I************** *************** *@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
>If you'd looked a little closer, you'd have found that C99's usage of the
word "abbreviate d" (which has the same root as "abbreviati on") clearly
disagrees with the way I was taught at school.
If you consider that root you will see that it consists of "ad" (to)
and "brevis" (short), so it's not surprising that it has a very
general meaning covering any kind of shortening. If it has a more
specific meaning amongst English teachers, they have failed to impose
it on the rest of us.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Aug 18 '08 #225
la************@ siemens.com said:
Richard Heathfield <rj*@see.sig.in validwrote:
>>
If you'd looked a little closer, you'd have found that C99's usage of
the word "abbreviate d" (which has the same root as "abbreviati on")
clearly disagrees with the way I was taught at school. (See 7.23.3.5(3)
for details.) Thus, this discussion has uncovered a flaw in the
Standard! So it seems it may conceivably have been worthwhile after all.
:-)

Are you sure it's a flaw in the standard rather than a flaw in your
schooling? :-)
Yeah. The chances of my having learned anything wrong at school are
basically zero. The teachers were perfect and knew everything.
My dictionary accepts any form of shortening as an abbreviation; an
abbreviation formed from the initial letters of words is either an
/acronym/ (if pronounceable) or an /initialism/ (if not).

What does the OED have to say?
The OED says "I cost £450". :-)

--
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 19 '08 #226
la************@ siemens.com writes:
Richard Heathfield <rj*@see.sig.in validwrote:
>>
If you'd looked a little closer, you'd have found that C99's usage of the
word "abbreviate d" (which has the same root as "abbreviati on") clearly
disagrees with the way I was taught at school. (See 7.23.3.5(3) for
details.) Thus, this discussion has uncovered a flaw in the Standard! So
it seems it may conceivably have been worthwhile after all. :-)

Are you sure it's a flaw in the standard rather than a flaw in your
schooling? :-)

My dictionary accepts any form of shortening as an abbreviation; an
abbreviation formed from the initial letters of words is either an
/acronym/ (if pronounceable) or an /initialism/ (if not).

What does the OED have to say?
abbreviation

1. The act of shortening, reducing in length.
2. The result of abbreviating; an abbreviated or reduced form; short
summary, abridgement.
3. esp. A shortened form of a spoken word, or written symbol; a part
of a word or symbol standing for the whole.

abbreviated

1. Shortened, cut short, in the various senses of the vb.

and so we also need:

abbreviate

To make shorter, shorten, cut short in any way.

3. trans. To shorten by cutting off a part; to cut short.
d. Of words spoken or written, or symbols of any kind: To contract,
so that a part stands for the whole. The common mod. use.

(Obsolete and obscure uses removed -- hence the missing numbers.)
This is from the on-line 1989 second edition.

--
Ben.
Aug 19 '08 #227
On Fri, 15 Aug 2008 14:37:57 -0700 (PDT), Paul Hsieh posted:
On Aug 14, 10:16*pm, s0s...@gmail.co m wrote:
>So let me see if I got this right...

Off-topic:

* - Networking in C
* - Threading in C
* - Creating directories in C
* - Future C standards
* - Programs written in C

You forgot:

- The general practice of programming and computer science
- C compilers
- Any real world program written in C outside of command line
utilities
- Comparisons of C with any other language
>On-topic:

* - Prototyping main()
* - (Not) casting malloc() calls
* - Proper use of English words
* - Nationalities abbreviations

You forgot:

- Complaining about google groups
- Complaining about signatures
- Bible study -- err, I mean ANSI standard recitations.
Funny stuff. I was perusing the later messages and thinking that "the
topic" had widened up.

Never heard of a usanian.
--
We must respect the other fellow's religion, but only in the sense and to
the extent that we respect his theory that his wife is beautiful and his
children smart. 5
H. L. Mencken
Aug 19 '08 #228
"Ian Collins" <ia******@hotma il.comwrote in message
news:6g******** *****@mid.indiv idual.net...
Chris M. Thomasson wrote:
>"Ian Collins" <ia******@hotma il.comwrote in message
news:6g******* ******@mid.indi vidual.net...
>>Richard Heathfield wrote:

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.

What happens if the driver hit the brakes for whatever reason, and the
seatbelt causes severe personal injury to the occupant(s) of the back
seat? Who gets to get sued?

I live in New Zealand, so nobody gets sued!
You mean there are no ambulance chasers in New Zealand?

;^)

Aug 19 '08 #229
Chris M. Thomasson wrote:
>
You mean there are no ambulance chasers in New Zealand?
Not really, we've managed to remain civilised so far...

--
Ian Collins.
Aug 19 '08 #230

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

Similar topics

101
3397
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
2842
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
18625
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
7469
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
9370
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
3580
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
9711
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
9593
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
10595
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
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9169
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...
1
7633
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
5529
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...
3
3001
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.