aboutsummaryrefslogtreecommitdiff
path: root/gdb/doublest.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/doublest.c')
-rw-r--r--gdb/doublest.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/gdb/doublest.c b/gdb/doublest.c
index 026cf42..fe06fec 100644
--- a/gdb/doublest.c
+++ b/gdb/doublest.c
@@ -693,6 +693,15 @@ static const struct floatformat *host_double_format = GDB_HOST_DOUBLE_FORMAT;
static const struct floatformat *host_long_double_format
= GDB_HOST_LONG_DOUBLE_FORMAT;
+/* See doublest.h. */
+
+size_t
+floatformat_totalsize_bytes (const struct floatformat *fmt)
+{
+ return ((fmt->totalsize + FLOATFORMAT_CHAR_BIT - 1)
+ / FLOATFORMAT_CHAR_BIT);
+}
+
void
floatformat_to_doublest (const struct floatformat *fmt,
const void *in, DOUBLEST *out)
@@ -802,12 +811,16 @@ const struct floatformat *
floatformat_from_type (const struct type *type)
{
struct gdbarch *gdbarch = get_type_arch (type);
+ const struct floatformat *fmt;
gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
if (TYPE_FLOATFORMAT (type) != NULL)
- return TYPE_FLOATFORMAT (type)[gdbarch_byte_order (gdbarch)];
+ fmt = TYPE_FLOATFORMAT (type)[gdbarch_byte_order (gdbarch)];
else
- return floatformat_from_length (gdbarch, TYPE_LENGTH (type));
+ fmt = floatformat_from_length (gdbarch, TYPE_LENGTH (type));
+
+ gdb_assert (TYPE_LENGTH (type) >= floatformat_totalsize_bytes (fmt));
+ return fmt;
}
/* Extract a floating-point number of type TYPE from a target-order