aboutsummaryrefslogtreecommitdiff
path: root/gdb/f-lang.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-10-04 20:47:06 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-10-25 14:51:44 -0400
commit50888e42dcd32b30e1144c0aa6d1c1490da45cd9 (patch)
tree72fad89d67057ecb53f26bac0464542829053e3e /gdb/f-lang.c
parentd9f82e931394efed68858eb7c7bb5832ad888482 (diff)
downloadgdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.zip
gdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.tar.gz
gdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.tar.bz2
gdb: change functions returning value contents to use gdb::array_view
The bug fixed by this [1] patch was caused by an out-of-bounds access to a value's content. The code gets the value's content (just a pointer) and then indexes it with a non-sensical index. This made me think of changing functions that return value contents to return array_views instead of a plain pointer. This has the advantage that when GDB is built with _GLIBCXX_DEBUG, accesses to the array_view are checked, making bugs more apparent / easier to find. This patch changes the return types of these functions, and updates callers to call .data() on the result, meaning it's not changing anything in practice. Additional work will be needed (which can be done little by little) to make callers propagate the use of array_view and reap the benefits. [1] https://sourceware.org/pipermail/gdb-patches/2021-September/182306.html Change-Id: I5151f888f169e1c36abe2cbc57620110673816f3
Diffstat (limited to 'gdb/f-lang.c')
-rw-r--r--gdb/f-lang.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 16ec9e0..1b5a99c 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -770,7 +770,7 @@ eval_op_f_abs (struct type *expect_type, struct expression *exp,
case TYPE_CODE_FLT:
{
double d
- = fabs (target_float_to_host_double (value_contents (arg1),
+ = fabs (target_float_to_host_double (value_contents (arg1).data (),
value_type (arg1)));
return value_from_host_double (type, d);
}
@@ -800,10 +800,10 @@ eval_op_f_mod (struct type *expect_type, struct expression *exp,
case TYPE_CODE_FLT:
{
double d1
- = target_float_to_host_double (value_contents (arg1),
+ = target_float_to_host_double (value_contents (arg1).data (),
value_type (arg1));
double d2
- = target_float_to_host_double (value_contents (arg2),
+ = target_float_to_host_double (value_contents (arg2).data (),
value_type (arg2));
double d3 = fmod (d1, d2);
return value_from_host_double (type, d3);
@@ -833,7 +833,7 @@ eval_op_f_ceil (struct type *expect_type, struct expression *exp,
if (type->code () != TYPE_CODE_FLT)
error (_("argument to CEILING must be of type float"));
double val
- = target_float_to_host_double (value_contents (arg1),
+ = target_float_to_host_double (value_contents (arg1).data (),
value_type (arg1));
val = ceil (val);
return value_from_host_double (type, val);
@@ -851,7 +851,7 @@ eval_op_f_floor (struct type *expect_type, struct expression *exp,
if (type->code () != TYPE_CODE_FLT)
error (_("argument to FLOOR must be of type float"));
double val
- = target_float_to_host_double (value_contents (arg1),
+ = target_float_to_host_double (value_contents (arg1).data (),
value_type (arg1));
val = floor (val);
return value_from_host_double (type, val);
@@ -883,10 +883,10 @@ eval_op_f_modulo (struct type *expect_type, struct expression *exp,
case TYPE_CODE_FLT:
{
double a
- = target_float_to_host_double (value_contents (arg1),
+ = target_float_to_host_double (value_contents (arg1).data (),
value_type (arg1));
double p
- = target_float_to_host_double (value_contents (arg2),
+ = target_float_to_host_double (value_contents (arg2).data (),
value_type (arg2));
double result = fmod (a, p);
if (result != 0 && (a < 0.0) != (p < 0.0))
@@ -1384,11 +1384,9 @@ fortran_undetermined::value_subarray (value *array,
array = value_at_lazy (array_slice_type,
value_address (array) + total_offset);
else
- array = value_from_contents_and_address (array_slice_type,
- (value_contents (array)
- + total_offset),
- (value_address (array)
- + total_offset));
+ array = value_from_contents_and_address
+ (array_slice_type, value_contents (array).data () + total_offset,
+ value_address (array) + total_offset);
}
else if (!value_lazy (array))
array = value_from_component (array, array_slice_type, total_offset);
@@ -1518,7 +1516,7 @@ fortran_structop_operation::evaluate (struct type *expect_type,
struct type *elt_type = value_type (elt);
if (is_dynamic_type (elt_type))
{
- const gdb_byte *valaddr = value_contents_for_printing (elt);
+ const gdb_byte *valaddr = value_contents_for_printing (elt).data ();
CORE_ADDR address = value_address (elt);
gdb::array_view<const gdb_byte> view
= gdb::make_array_view (valaddr, TYPE_LENGTH (elt_type));
@@ -1746,10 +1744,9 @@ fortran_argument_convert (struct value *value, bool is_artificial)
const int length = TYPE_LENGTH (type);
const CORE_ADDR addr
= value_as_long (value_allocate_space_in_inferior (length));
- write_memory (addr, value_contents (value), length);
- struct value *val
- = value_from_contents_and_address (type, value_contents (value),
- addr);
+ write_memory (addr, value_contents (value).data (), length);
+ struct value *val = value_from_contents_and_address
+ (type, value_contents (value).data (), addr);
return value_addr (val);
}
else