aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-08-28 13:39:33 -0600
committerTom Tromey <tromey@adacore.com>2023-08-29 13:36:55 -0600
commit9c00ec6fe09c01df6d30fd67c3b12ee99394ee71 (patch)
treea907fcbc2ed41111130901c6b6aa455a8d95423a /gdb
parent0f2d28db8e9c7a6b598370a2a93bcb9ae7f0df96 (diff)
downloadgdb-9c00ec6fe09c01df6d30fd67c3b12ee99394ee71.zip
gdb-9c00ec6fe09c01df6d30fd67c3b12ee99394ee71.tar.gz
gdb-9c00ec6fe09c01df6d30fd67c3b12ee99394ee71.tar.bz2
Hoist array bounds check in array_operation::evaluate
This hoists the array bounds check in array_operation::evaluate to before the loop. Reviewed-by: John Baldwin <jhb@FreeBSD.org> Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/eval.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/gdb/eval.c b/gdb/eval.c
index 63c414e..6cf7254 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2426,6 +2426,8 @@ array_operation::evaluate (struct type *expect_type,
low_bound = 0;
high_bound = (type->length () / element_size) - 1;
}
+ if (low_bound + nargs - 1 > high_bound)
+ error (_("Too many array elements"));
index = low_bound;
memset (array->contents_raw ().data (), 0, expect_type->length ());
for (int tem = 0; tem < nargs; ++tem)
@@ -2436,9 +2438,6 @@ array_operation::evaluate (struct type *expect_type,
exp, noside);
if (element->type () != element_type)
element = value_cast (element_type, element);
- if (index > high_bound)
- /* To avoid memory corruption. */
- error (_("Too many array elements"));
memcpy (array->contents_raw ().data ()
+ (index - low_bound) * element_size,
element->contents ().data (),