Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: sscanf error checking Date: Thu, 15 Dec 2016 11:26:41 -0800 Organization: None to speak of Lines: 37 Message-ID: References: <77a15075-1f22-405c-a896-061dda988473@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="d13fb784dfa5b4f5223d68f3ab06c5fb"; logging-data="11406"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gudlbnUOKCx/IZw2Cp00i" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:/AlJwXn+CdW/RhunNPWJtVDiEog= sha1:Xdij/H0IEfoyKD10iqyu/YG4V8M= Xref: csiph.com comp.lang.c:99550 supercat@casperkitty.com writes: > 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. Many programs are poorly written. That's often why malware is able to work. > Unless > an implementation decides to jump the rails when given invalid input > (something which the Standard doesn't forbid, but which I don't think > it ever intended to encourage) the semantics of scanf may be adequate > for use in such contexts. scanf() in particular reads only from standard input, which is typically under the control of the user, not of the programmer. Even sscanf() and fscanf() allow you to check for errors *other than* numeric overflow, and users are routinely advised that they should always check the value returned by any of the *scanf() functions rather than assuming valid input. Why should there be no way to detect or handle numeric overflow in particular? I think the strto*() functions are probably newer than the *scanf() functions. I speculate that checking for numeric overflow was considered an excessive burden on implementers when the *scanf() functions were first implemented and specified. It is my strong opinion that that excuse no longer applies. -- Keith Thompson (The_Other_Keith) kst-u@mib.org 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"