Crash in FP printing code
Ulrich Drepper
drepper@redhat.com
Mon Sep 15 08:06:00 GMT 2003
Jakub Jelinek wrote:
> This is bogus, vasprintf takes va_list, not long double *. You really should
> never assume what va_list is.
If you'd use
#include <stdarg.h>
int data[] = {0x00000000, 0x80000000, 0x00000cd0};
struct ieee {
unsigned int mantissa1:32;
unsigned int mantissa0:30;
unsigned int quiet_nan:1;
unsigned int one:1;
unsigned int exponent:15;
unsigned int negative:1;
unsigned int empty:16;
} *pieee = data;
long double *doub = (long double *) data;
void foo (int a, ...)
{
va_list va;
va_start (va, a);
char *ret = 0;
vasprintf (&ret, "%.35Lg", va);
printf ("%s\n", ret);
}
int main()
{
char *ret = 0;
printf ("%.35Lg\n", *doub);
asprintf (&ret, "%.35Lg", *doub);
printf ("%s\n", ret);
foo (1, *doub);
}
you'd see everything works as expected. See also the definition of
'data' with the extra bit set. Anything else is invalid code and
according to the GIGO principle you get what you deserve.
--
--------------. ,-. 444 Castro Street
Ulrich Drepper \ ,-----------------' \ Mountain View, CA 94041 USA
Red Hat `--' drepper at redhat.com `---------------------------
More information about the Libc-alpha
mailing list