K
kuyper
Richard said:It is simple enough to see the issue with it : the main issue is that
it is there and needs to remain there to support legacy code. I dont
think the standards commitee will pay for millions of lines to have
system specific handwritten gets() to replace the old one or, god
forbid, to change all the calls themselves to do boundary checks and
use something more robust.
What is the process for C to depreciate something like this? Is it a
new flag to switch it on? ....
Like a lot of buggy old stuff, the people who used it were often not so
stupid and made big enough buffers to cope with the declared range of
inputs. Perfect? No. But worked for them at the time.
The problem occurs when inputs outside the declared range are provided.
No C program has sufficient portable control over it's standard input
to guarantee that this won't happen. Of course, not all programs need
to be portable, and there are non-portable ways to obtain sufficient
control.
I don't think it's good design for a C program to ever have undefined
behavior. When given inputs that are outside it's declared range, it
should fail gracefully. By gracefully, I mean that it should provide
error message in the appropriate log file or stderr, or at least return
a checkable error status to the calling environment. Even if that's not
possible, "failing gracefully" means, as an absolute minimum, that the
behavior of the program is not undefined. It's not possible to use
gets() in a portable fashion while conforming to this guideline.