This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Silently passing wrong input for good one
- From: Paolo Carlini <pcarlini at suse dot de>
- To: Roberto Bagnara <bagnara at cs dot unipr dot it>
- Cc: libstdc++ at gcc dot gnu dot org,The Parma Polyhedra Library developers' list <ppl-devel at cs dot unipr dot it>
- Date: Fri, 21 Oct 2005 20:11:51 +0200
- Subject: Re: Silently passing wrong input for good one
- References: <4359213C.9060503@cs.unipr.it>
Hi Roberto,
> the program below, when compiled with GCC 4.0.2 and
> given the input "-3e-abcd", prints
>
> input = `-3e-abcd'
> good
> f = -3
> left = `abcd'
I changed this behavior during the 3.4.x development cycle (3.3.x did
behave like Comeau), see testcase num_get/get/char/10.cc. Basically, my
rationale was that of matching as closely as possible the usual usage of
scanf in C: if '-3e-' is handed to scanf, it definitely assigns -3.0 and
the user happily proceeds.
Then, we come to the detailed interpretation of C++ 22.2.2.1.2/11, where
it says: "would have caused scanf to report an input failure". In my
reading of the C standard (frankly, I have available only C99, which
sometimes is subtly different from C90, the real reference), an input
failure is a very specific kind of failure (see 7.19.6.2/4), which may
lead to scanf returning EOF (7.19.6.2/16).
Anyway, more generally, if I read again the entire 7.19.6.2 (in
particular /9 is important when it defines an input item as *a prefix*
of a matching input sequence), I don't see how possibly a scanf of a
single float can *fail* (either input failure or matching failure) when
'-3e-' is passed. Indeed, in practice, it assigns the value and returns
1, nothing externally visible signals that something went wrong.
Paolo.