glibc segfault on "special" long double values is _ok_!?
Jan-Benedict Glaw
jbglaw@lug-owl.de
Thu Jun 7 22:53:00 GMT 2007
On Thu, 2007-06-07 13:57:17 -0400, Tor Myklebust <tmyklebu@csclub.uwaterloo.ca> wrote:
> On Thu, 7 Jun 2007, Jan-Benedict Glaw wrote:
> >There's a difference in
> >
> > void send_float (float foo, int fd) {
> > write (fd, &foo, sizeof (float));
> > }
> >
> >and
> >
> > void send_float (float foo, int fd) {
> > char buf[100];
> > snprintf (buf, sizeof (buf), "%f", foo);
> > write (fd, buf, strlen (buf));
> > }
> >
> >The second variant surely burns more CPU cycles, even on both sides,
> >but it'll easily work even for different architectures. (I just think
> >about VAX where the CPU FP support is made up of four non-IEEE float
> >types...)
>
> And the second variant can segfault if you replace 'float' by 'long
> double' (changing the format string appropriately) and you feed it
> something bad. Why is this a good thing?
Where shall this invalid long double come from? The CPU won't generate
it itself. And if you play tricks and printf() a known-bad long double
from inside your application, that app doesn't deserve any better than
crash.
MfG, JBG
--
Jan-Benedict Glaw jbglaw@lug-owl.de +49-172-7608481
Signature of: The course of history shows that as a government grows, liberty
the second : decreases." (Thomas Jefferson)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20070607/1e109298/attachment.sig>
More information about the Libc-alpha
mailing list