gets() - dangerous?

K

Kenny McCormack

James said:
I use gets() everyday! [...]
[...] The input to my gets()
is coming from a file I or my software created, and which has
frequent line-feeds. The buffer into which I gets() is ten times
as big as necessary. [...]

Semi-rhetorical question: If you're sure that the
file's lines are of reasonable length, why make the
buffer ten times larger than needed? Pascal's Wager?

For the same reason most people use safety belts in cars.
 
M

Malcolm

Richard Heathfield said:
Well, I could go on to address the other crits if I could be bothered. Let
the Wikids put the above right first. At present, I cannot recommend the
Wiki's C article to anyone. It is, quite simply, riddled with wrongs.
I've now read the article.

The basic problem is that the writer doesn't understand that his criticisms
are mostly the inevitable consequence of having direct memory addressing,
and not allowing lengthy operations like garbage collection.

It is a bit like criticising a petrol car for having a gearbox. Gears are a
nuisance, they break down, they waste energy. Electric cars don't need them.
But electric cars have other disadvantages, and it is virtutally impossible
to build a petrol engine that doesn't need gears.
 
K

Kenny McCormack

I've now read the article.

The basic problem is that the writer doesn't understand that his criticisms
are mostly the inevitable consequence of having direct memory addressing,
and not allowing lengthy operations like garbage collection.

It is a bit like criticising a petrol car for having a gearbox. Gears are a
nuisance, they break down, they waste energy. Electric cars don't need them.
But electric cars have other disadvantages, and it is virtutally impossible
to build a petrol engine that doesn't need gears.

I think both of you guys are too emotionally invested in this.

The article was just making the point that C/C++ (*) is not a baby-safe
language. There's nothing wrong with that, it just means that C/C++ are
like chainsaws - very dangerous in inept hands. And, industry wants safe
langauges, that inept, low skilled labor can use.

Anecdotally, I will say that when I learned my first assembly language (a
couple of million years ago), the first thing that really shocked me was
the fact that it wasn't baby-safe - that I could do totally undefined
things and get totally obscure error messages from doing so. I think
that's the primary difference between languages like C/C++ (and, as it
turns out, many dialects of Pascal as well [*]) and "user-proof" languages
like BASIC - that is, that you can get obscure (and basically useless)
error messages like "Segmentation Violation", when you do something stupid.

(*) Yes, I know it is doctrine around here that C and C++ are two different
languages and that it is heresy to speak of them as a slashed entity like
this. But C++ has all the same "non-user-proof" features that C has, and
so, I think, for the sake of this thread, we can treat them thusly (as
a "slashed entity"). In particular, I know that Richard was trying to say
that Wikipedia was being unfair to C and biased towards C++, but I think we
all understand that most of the criticisms of C apply equally well to C++.

[*] Again, lest you think I am favoring Pascal at C's expense.
 
R

Richard Heathfield

Kenny McCormack said:
I think both of you guys are too emotionally invested in this.

There's nothing particularly emotional about it. The Wiki article is just
plain wrong.
 
K

Kenny McCormack

Kenny McCormack said:


There's nothing particularly emotional about it. The Wiki article is just
plain wrong.

No, it isn't. But thank you for playing our game.
 
R

Richard Heathfield

Kenny McCormack said:
No, it isn't.

Yes, it is. (etc etc)

And if you browse around the Wiki for a while, you'll find other articles on
C, each of which has their own little collection of mistakes.
 
K

Kenny McCormack

Kenny McCormack said:


Yes, it is. (etc etc)

And if you browse around the Wiki for a while, you'll find other articles on
C, each of which has their own little collection of mistakes.

I suspect you didn't read my other post, in which I explain at some length,
the context in which the Wiki article was written. Once you do that,
you'll understand.
 
J

Jordan Abel

Kenny McCormack said:


Yes, it is. (etc etc)

And if you browse around the Wiki for a while, you'll find other articles on
C, each of which has their own little collection of mistakes.

Such as? (Yes, he's a troll, but you haven't given any specific examples
of facts claimed that are false, and the article really doesn't look to
me as bad as you claim it is)
 
R

Richard Bos

No, it isn't. But thank you for playing our game.

Programming is not a game. It may surprise you, but occasionally there
actually _are_ lives at stake.

Wikipedia _is_ a game. That is basically the whole problem.

Richard
 
W

Walter Roberson

The article was just making the point that C/C++ (*) is not a baby-safe
language. There's nothing wrong with that, it just means that C/C++ are
like chainsaws - very dangerous in inept hands. And, industry wants safe
langauges, that inept, low skilled labor can use.
I think
that's the primary difference between languages like C/C++ (and, as it
turns out, many dialects of Pascal as well [*]) and "user-proof" languages
like BASIC - that is, that you can get obscure (and basically useless)
error messages like "Segmentation Violation", when you do something stupid.

I haven't looked at any of the modern BASICs, but the BASICs that
I grew up with were not "user-proof". PEEK and POKE were used
for a lot of system dependancies, including a lot of graphics;
and in those days it was common to encode machine language in
DATA statements and then branch to it.
 
R

Richard Heathfield

Kenny McCormack said:
I suspect you didn't read my other post

That is almost certainly true. If you want to be taken seriously and have
people read your stuff, you need to start acting a bit more seriously. I'm
not about to go hunting for your "other post" in a feed the size of clc, if
it means wading through your trollisms.
 
R

Richard Heathfield

Jordan Abel said:
Such as? (Yes, he's a troll, but you haven't given any specific examples
of facts claimed that are false, and the article really doesn't look to
me as bad as you claim it is)

I've already pointed out several faults with the lead article.

Observe the first program example on this page:

<http://en.wikipedia.org/wiki/C_syntax>

Further down this page, it gives the following example program:

void setInt(int **p, int n)
{
*p = (int *) malloc(sizeof(int)); // allocate a memory area, using
the pointer given as as a parameter [1]

**p = n;
}

int main(void)
{
int *p; // create a pointer to an integer
setInt(&p, 42); // pass the address of 'p'
return 0;
}

[1] Originally presented as a single line.

If this is C90 code, count the bugs.
If it's C99 code instead, count the bugs.

Here's their example of a scanf call:

int x;
scanf("%d", &x);

Not even my cat would use scanf like that. (The kitten might.)

These are not the only problems, by any means. Now, if you want to find any
more, go look for yourself.
 
N

Netocrat

Mark McIntyre replied:
<OT> (on-topic info follows)
There is, as on Usenet, the "eternal vigilance" of those citizens
responsible enough to assume it. This simple model protects against a
malicious controlling minority. The Britannica model isn't as good at
that, but it apparently does protect better against corruption by random
malicious/ignorant individuals.

Wikipedia is afaict considering the need for a middle ground, especially
for topics where the honest and informed are not more numerous and more
active than the malicious/ignorant.
</OT>

Richard Heathfield adds:
[Take a look at the Wikipedia C article], and you'll see a "criticisms"
section - which is not something I noticed in the C++, Python or Lisp
sections. Does this mean those languages are beyond criticism? Or does
it simply mean the Wikids don't understand C very well?

<still OT>
It could also mean that as a knowledgeable C programmer and author, this
is a prime area for exercise of your democratic responsibility for
vigilance against disinformation, and for public debate on correctness.
Elsewhere you presented several (IMO useful) ideas for improving the
article; Wikipedia's policy allows for a neutral "supporters vs critics"
debate, so you needn't view it as all-or-nothing:
<http://tinyurl.com/7uppc>
</OT>

To the topical: the c.l.c community itself can explore the issue of
structured vs open wiki access - the proposed wiki [1] hasn't disappeared,
it's just been worked on quietly for a while.[2]

Software support for the maintenance of an editorial group has been
written and installed.[3] The proposed wiki charter has further
details.[4]

No content other than planning yet exists within the wiki, although there
are clear ideas of what the content will be.[5] To import the K&R2
solutions from Richard Heathfield's unmaintained site (as discussed in a
previous thread), a script has been written.[6]

Now that basic support for moderation exists, feedback, particularly from
regulars, and in particular from Steve Summit as FAQ maintainer and
copyright holder, is solicited:
* do you support the proposed charter and model of a limited editorial
group?
* do you support the proposed content guidelines?
* is it acceptable/desirable to host the comp.lang.c FAQ on such a wiki?
* any other issues/concerns.

If concerted objections arise, likely the wiki will be continued under
an unofficial title, focusing on unique content, until (if at all) the
objections can be resolved. The current wiki permissions are quite open
so that contribution during the planning stage is easier: no edits are
blocked other than anonymous editing and a few selected pages.

The entry point to the wiki is:
<http://clc.flash-gordon.me.uk/wiki/Main_Page>.

[1] Original clc FAQ wiki thread: <http://tinyurl.com/7q3eh>
[2] <http://clc.flash-gordon.me.uk/wiki/Planning:Status>
[3] A decisions and voting extension supports a self-regulating editorial
group with members automatically added and removed by group decision. See
the links immediately above and below for details. The level of
sophistication is presently quite low but development is ongoing.
[4]<http://clc.flash-gordon.me.uk/wiki/Planning:Proposed_Charter>
[5]<http://clc.flash-gordon.me.uk/wiki/Planning:Proposed_Content_Guidelines>
[6] Good-faith efforts are being made to obtain all contributors'
permission prior to running the script. Please respond (email is fine) if
you are on the list linked to here:
<http://clc.flash-gordon.me.uk/wiki/Planning:Missing_Permissions> and wish
to assert or deny permission. Non-response may ultimately be taken as
implicit permission.
 
K

Kenny McCormack

Walter Roberson said:
I haven't looked at any of the modern BASICs, but the BASICs that
I grew up with were not "user-proof". PEEK and POKE were used
for a lot of system dependancies, including a lot of graphics;
and in those days it was common to encode machine language in
DATA statements and then branch to it.

I was using BASIC long before there were such things as microcomputers
(aka, PCs). *Real* BASIC on *real* computers (w/o PEEK/POKE/etc) was/is
a baby-proof environment.

And even you can see that if you invoke machine language from within BASIC,
well, then you're not programming in BASIC anymore.
 
K

Kenny McCormack

(I wrote)
Programming is not a game. It may surprise you, but occasionally there
actually _are_ lives at stake.

Luckily, they don't use anything written by MS.
Wikipedia _is_ a game. That is basically the whole problem.

Exactly my point. That's why I said "thank you for playing our (Wikipedia)
game."

Thank you ever so much for making my point.
 
K

Kenny McCormack

Jordan Abel said:


I've already pointed out several faults with the lead article.

Observe the first program example on this page:

<http://en.wikipedia.org/wiki/C_syntax>

The general tone of Wiki is "articles written by 'informed laymen'" - that
is, at sort of the "college football level" (obscure reference - I'll
explain if needed). It is not reasonable to expect them to be done to the
level of religious-fervor/dot-all-the-Is-cross-all-the-Ts level that is
common/expected in this newsgroup.

(snip a whole bunch of stuff related to the usual CLC "Don't cast the
return value of malloc" and other such trivia)
 
R

Richard Heathfield

Kenny McCormack said:
The general tone of Wiki is "articles written by 'informed laymen'" - that
is, at sort of the "college football level" (obscure reference - I'll
explain if needed).

Fine, but that's just another way of saying "Wikipedia is not and never will
be authoritative and does not perceive accuracy as being the primary goal".
It is not reasonable to expect them to be done to the
level of religious-fervor/dot-all-the-Is-cross-all-the-Ts level that is
common/expected in this newsgroup.

It's not reasonable to expect them to get stuff right? Okay. That tells us
all we need to know about Wikipedia, I guess.
 
K

Kenny McCormack

Kenny McCormack said:


Fine, but that's just another way of saying "Wikipedia is not and never will
be authoritative and does not perceive accuracy as being the primary goal".

In the real world, there is a difference between accuracy and pedantry.
I (and most reasonable people, that is, those outside of the so-called
"regulars" in this weird ng) claim that the Wiki article about C is
accurate in the parts that matter. That it doesn't measure up to the level
of pedantry required of posters in this group is not particularly relevant.
It's not reasonable to expect them to get stuff right? Okay. That tells us
all we need to know about Wikipedia, I guess.

In the real world, there is a difference between accuracy and pedantry.

This newsgroup is a nice little haven for people who can't tell the
difference.
 
R

Richard Heathfield

Kenny McCormack said:
In the real world, there is a difference between accuracy and pedantry.

"Pedantry" is just a word used by people who don't care about accuracy to
describe the attitude of those people who do.
I (and most reasonable people, that is, those outside of the so-called
"regulars" in this weird ng) claim that the Wiki article about C is
accurate in the parts that matter.

The claim, however, is incorrect.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top