Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: sscanf error checking |
| Date | 2016-12-15 12:33 -0800 |
| Organization | None to speak of |
| Message-ID | <lnlgvhkk4w.fsf@kst-u.example.com> (permalink) |
| References | <o2rp71$3e7$1@dont-email.me> <k2c35ctbq4lg3bnllpfbt15lc8l2qsfodm@4ax.com> <77a15075-1f22-405c-a896-061dda988473@googlegroups.com> <5852fa62.4681734@news.xs4all.nl> |
raltbos@xs4all.nl (Richard Bos) writes:
> supercat@casperkitty.com wrote:
>> On Wednesday, December 14, 2016 at 2:52:04 PM UTC-6, robert...@yahoo.com wrote:
>> > IMO, the *scanf() and ato*() functions are pretty much of no use
>> > outside of toy problems, the lack of meaningful error handling being
>> > the biggest issue. YMMV.
>>
>> Many programs are intended only for use upon validated input.
>
> There is no such thing as validated input; there is only _temporarily_
> validated input.
>
> A program using scanf()# and ato*() is only safe if:
> - it is used with a single set of input;
> - that input is validated _instantly_ before it is fed to the program;
> - the program is deleted or incapacitated immediately afterward.
scanf() can, with some care, be used safely for non-numeric input.
But the hassle of doing so can easily exceed the cost of using
an alternative.
> (A program using gets() is, of course, unsafe even then.)
In the circumstances you suggest, gets() *could* be used safely. As
long as the input line doesn't exceed the size of the buffer, it has
well defined behavior. Of course the conditions you suggest are
(deliberately) unrealistic, and it's not at all difficult to write code
that doesn't depend on them (if nothing else, fgets() followed by
deleting any trailing '\n').
> # sscanf() and fscanf() are _slightly_ better.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
sscanf error checking BartC <bc@freeuk.com> - 2016-12-14 15:42 +0000
Re: sscanf error checking John Gordon <gordon@panix.com> - 2016-12-14 15:58 +0000
Re: sscanf error checking Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2016-12-14 11:14 -0500
Re: sscanf error checking gazelle@shell.xmission.com (Kenny McCormack) - 2016-12-14 16:11 +0000
Re: sscanf error checking BartC <bc@freeuk.com> - 2016-12-14 17:51 +0000
Re: sscanf error checking gazelle@shell.xmission.com (Kenny McCormack) - 2016-12-14 18:09 +0000
Re: sscanf error checking Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-14 19:49 +0000
Re: sscanf error checking BartC <bc@freeuk.com> - 2016-12-14 20:43 +0000
Re: sscanf error checking Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-12-14 16:40 +0000
Re: sscanf error checking Keith Thompson <kst-u@mib.org> - 2016-12-14 09:34 -0800
Re: sscanf error checking Robert Wessel <robertwessel2@yahoo.com> - 2016-12-14 14:52 -0600
Re: sscanf error checking supercat@casperkitty.com - 2016-12-15 07:24 -0800
Re: sscanf error checking Keith Thompson <kst-u@mib.org> - 2016-12-15 11:26 -0800
Re: sscanf error checking Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-15 15:35 -0800
Re: sscanf error checking Keith Thompson <kst-u@mib.org> - 2016-12-15 16:28 -0800
Re: sscanf error checking Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-12-15 16:37 -0800
Re: sscanf error checking Robert Wessel <robertwessel2@yahoo.com> - 2016-12-26 17:25 -0600
Re: sscanf error checking supercat@casperkitty.com - 2016-12-15 16:38 -0800
Re: sscanf error checking raltbos@xs4all.nl (Richard Bos) - 2016-12-15 20:20 +0000
Re: sscanf error checking Keith Thompson <kst-u@mib.org> - 2016-12-15 12:33 -0800
sscanf error checking asetofsymbols@gmail.com - 2016-12-16 01:49 -0800
sscanf error checking asetofsymbols@gmail.com - 2016-12-16 01:53 -0800
csiph-web