Re: [RFA/mips] Fix crash trying to print long double float

Joel Brobecker
2004-08-06T20:38:37Z

> Does the attached stop the crash?

I will give it a go sometime this evening, but yes, I think it will
prevent the crash. It's a good general guard.

> 2004-08-06 Andrew Cagney <cagney@gnu.org>
>
> * doublest.c: Update copyright.
> (floatformat_from_length): Call error when floatformat is NULL.
> (extract_floating_by_length): Remove NULL fmt check.
> (store_floating_by_length): Ditto.

One question:

> @@ -633,12 +633,13 @@ floatformat_from_doublest (const struct
> static const struct floatformat *
> floatformat_from_length (int len)
> {
> + const struct floatformat *format;
> if (len * TARGET_CHAR_BIT == TARGET_FLOAT_BIT)
> - return TARGET_FLOAT_FORMAT;
> + format = TARGET_FLOAT_FORMAT;
> else if (len * TARGET_CHAR_BIT == TARGET_DOUBLE_BIT)
> - return TARGET_DOUBLE_FORMAT;
> + format = TARGET_DOUBLE_FORMAT;
> else if (len * TARGET_CHAR_BIT == TARGET_LONG_DOUBLE_BIT)
> - return TARGET_LONG_DOUBLE_FORMAT;
> + format = TARGET_LONG_DOUBLE_FORMAT;
> /* On i386 the 'long double' type takes 96 bits,
> while the real number of used bits is only 80,
> both in processor and in memory.
> @@ -646,9 +647,13 @@ floatformat_from_length (int len)
> else if ((TARGET_LONG_DOUBLE_FORMAT != NULL)
> && (len * TARGET_CHAR_BIT ==
> TARGET_LONG_DOUBLE_FORMAT->totalsize))
> - return TARGET_LONG_DOUBLE_FORMAT;
> -
> - return NULL;
> + format = TARGET_LONG_DOUBLE_FORMAT;
> + else
> + format = NULL;
> + if (format == NULL)
> + error ("This GDB does not support %d-bit floating-point values.",
> + len & TARGET_CHAR_BIT);
> + return format;
> }

Why do you use a variable? wouldn't have it been simpler to
add one line at the end like this:

error ("bla bla bla");
return NULL; /* Will never be reached. */

--
Joel