aboutsummaryrefslogtreecommitdiff
path: root/gdb/valops.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-08-29 09:14:01 -0600
committerTom Tromey <tromey@adacore.com>2023-08-29 13:36:55 -0600
commitb47331bf901065e051d6490105a61e677cafc451 (patch)
treec6fd7f523e1f1aecb574085d6e7965358aa6fb60 /gdb/valops.c
parent8b2ac9b21649a9c7f9edecfd817e9d10f20158c0 (diff)
downloadbinutils-b47331bf901065e051d6490105a61e677cafc451.zip
binutils-b47331bf901065e051d6490105a61e677cafc451.tar.gz
binutils-b47331bf901065e051d6490105a61e677cafc451.tar.bz2
Remove "highbound" parameter from value_array
value_array requires the passed-in bounds to match the length of the array_view it is given. This patch removes the redundant "highbound" parameter. Reviewed-by: John Baldwin <jhb@FreeBSD.org> Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb/valops.c')
-rw-r--r--gdb/valops.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/gdb/valops.c b/gdb/valops.c
index 1133049..6404091 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1684,18 +1684,16 @@ value_ind (struct value *arg1)
/* Create a value for an array by allocating space in GDB, copying the
data into that space, and then setting up an array value.
- The array bounds are set from LOWBOUND and HIGHBOUND, and the array
- is populated from the values passed in ELEMVEC.
+ The array bounds are set from LOWBOUND and the size of ELEMVEC, and
+ the array is populated from the values passed in ELEMVEC.
The element type of the array is inherited from the type of the
first element, and all elements must have the same size (though we
don't currently enforce any restriction on their types). */
struct value *
-value_array (int lowbound, int highbound,
- gdb::array_view<struct value *> elemvec)
+value_array (int lowbound, gdb::array_view<struct value *> elemvec)
{
- int nelem;
int idx;
ULONGEST typelength;
struct value *val;
@@ -1704,28 +1702,23 @@ value_array (int lowbound, int highbound,
/* Validate that the bounds are reasonable and that each of the
elements have the same size. */
- nelem = highbound - lowbound + 1;
- if (nelem <= 0)
- {
- error (_("bad array bounds (%d, %d)"), lowbound, highbound);
- }
typelength = type_length_units (elemvec[0]->enclosing_type ());
- for (idx = 1; idx < nelem; idx++)
+ for (struct value *other : elemvec.slice (1))
{
- if (type_length_units (elemvec[idx]->enclosing_type ())
- != typelength)
+ if (type_length_units (other->enclosing_type ()) != typelength)
{
error (_("array elements must all be the same size"));
}
}
arraytype = lookup_array_range_type (elemvec[0]->enclosing_type (),
- lowbound, highbound);
+ lowbound,
+ lowbound + elemvec.size () - 1);
if (!current_language->c_style_arrays_p ())
{
val = value::allocate (arraytype);
- for (idx = 0; idx < nelem; idx++)
+ for (idx = 0; idx < elemvec.size (); idx++)
elemvec[idx]->contents_copy (val, idx * typelength, 0, typelength);
return val;
}
@@ -1734,7 +1727,7 @@ value_array (int lowbound, int highbound,
copying in each element. */
val = value::allocate (arraytype);
- for (idx = 0; idx < nelem; idx++)
+ for (idx = 0; idx < elemvec.size (); idx++)
elemvec[idx]->contents_copy (val, idx * typelength, 0, typelength);
return val;
}