D
Default User
Willem said:Antoninus Twink wrote:
) Usually these "complaints" are just the observation
Suppose you're driving
Please don't feed the troll.
Brian
Willem said:Antoninus Twink wrote:
) Usually these "complaints" are just the observation
Suppose you're driving
James said:.... snip about gets ...
Whenever I build the Index to the Fabulous Pedigree
http://fabpedigree.com/altix.htm
I do several hundred thousand gets()'s, but none of them are
"dangerous". I live with a few "dangerous" messages during the
build (although I'm sure the pedants would prefer that each of
the several hundred thousand gets()'s produced its own such
message.![]()
Willem said:
They might also suffer the even more traumatic experience of having you
smash through their windscreen, injuring or even killing them.
And possibly their own.
CBFalconer said:They're all dangerous. For example, a one bit error in reading a
'\n' from your prewritten data can blow everything.
I assume you use it because of the simplicity of the call. You can
get that simplicity, together with safety, by using ggets.
The way to get rid of the warning on gets(), if you really want to
do it, is (on FreeBSD, anyway, but I suspect it applies to other
systems that use gcc as a default compiler):
(1) Remove the call to __warn_references() in gets.c .
(2) Rebuild the C library.
Rebuilding the compiler isn't necessary.
How does ggets overcome the problem you've just identified with the
OP's use of gets?
Ben said:How does ggets overcome the problem you've just identified with
the OP's use of gets?
Richard said:.... snip ...
Again, I stress that there is no shame in an input routine not
detecting bit errors of this kind. But ggets was offered, by its
author, as a solution to the problem of a one bit error in
reading a '\n' - and it is no such thing.
It doesn't - insofar as it makes no special provision against one-bit
errors in reading a '\n' from your prewritten data. It does, however,
return an error if it runs out of memory. But it fails to take the obvious
precaution of allowing the caller to specify an upper limit to the number
of bytes taken from the stream.
So let's say you have this situation - you know your lines are no longer
than 6 bytes (the same argument applies to more typical line lengths, eg
72 or 80, but the much lower value is chosen simply because it is easy to
write and easy to read in a Usenet article).
Here are your data:
3.141
1.618
A one bit error in reading a '\n' from the 3.141 line results in it being
interpreted as a J instead (01001010 instead of 00001010). So if ggets
really did overcome this obstacle, it would detect the one-bit error and
correct for it or at least report it. In practice, what ggets will do is
read the next line too, so that you'll get:
Andrew Poelstra said:ggets() interally allocates a dynamically-resized buffer. In the case
that it runs out of memory, it returns an appropriate error
condition.
CBFalconer said:I suggest you download it and see for yourself. It is only about
an 11k download.
They're all dangerous. For example, a one bit error in reading a
'\n' from your prewritten data can blow everything.
Usually these "complaints" are just the observation that
self-determination is a pretty fundamental liberty that we should have
in a free society. The state has *no damn business* telling me what I
should or shouldn't do in the privacy of my own car, when it doesn't
affect anyone's safety but my own.
Richard said:CBFalconer said:
Then I am at a loss to explain your previous response.
Perhaps you could explain how such an error could blow up one's
machine in the first place.
What is this one bit error you are talking about?
You've snipped the "problem" so my objection has been lost. What I
was saying (and it is a bit of a wild card) is how can any routine be
safe in the presence of bit errors in the input? I don't think it is
reasonable to assume that stdio works under these conditions. We have
no reasonable method to reason about what a program does when the
input system does not deliver the input.
I'd use fgets even for a "throwaway" program because it's really as easy
to use and I won't have to worry about carefully deleting the sources
later.
You've snipped the "problem" so my objection has been lost. What I
was saying (and it is a bit of a wild card) is how can any routine be
safe in the presence of bit errors in the input?
... I don't think it is
reasonable to assume that stdio works under these conditions. We have
no reasonable method to reason about what a program does when the
input system does not deliver the input.
[...]Richard Heathfield said:CBFalconer said:
Then I am at a loss to explain your previous response.
Perhaps you could explain how such an error could blow up one's machine in
the first place.
James Kuyper said:Ben Bacarisse wrote:
...
By writing the routine so that, no matter what the input is, it never
has undefined behavior. This means validating all inputs before using
them in any context where an invalid value could result in undefined
behavior. The possibility of erroneous input is an unavoidable fact of
life; code which cannot deal with that fact safely is poorly designed.
What is "safely"? That is something for the designer to
decide. However, for code which is meant to be portable, "safely" is
incompatible with undefined behavior, because the designer inherently
cannot have decided what that behavior will be. For code which is, as
a matter of deliberate intent, portable only to a limited range of
implementations, code with behavior which is undefined by the standard
can still count as "safe", so long as the behavior of that code is
defined by all of the implementations it is supposed to be portable
to.
I think you're going overboard by assuming that a single corrupted bit
in an input necessarily renders the entire system
untrustworthy.
Hardware can fail, and the failure is not always
detectable. A single undetected failure in the hardware associated
with a disk drive or in the network connection to an NFS mounted drive
does not, in general, justify assuming that any other component of the
system has failed. It doesn't even justify automatically assuming that
there will be a catastrophic failure of the component that was
malfunctioning (though that is certainly a possibility to
consider). In particular, it doesn't justify assuming that the
routines declared in <stdio.h> are defective.
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.