aboutsummaryrefslogtreecommitdiff
path: root/gdb/valops.c
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2019-05-23 19:49:41 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2019-06-10 23:05:58 +0100
commita7067863418451b27130bb4300ac1890ff806c12 (patch)
tree6df484c1278ac2e041d584b6a411d629b3e9abab /gdb/valops.c
parent9ab084121f50a6858b7298de6c5326cee3687c43 (diff)
downloadbinutils-a7067863418451b27130bb4300ac1890ff806c12.zip
binutils-a7067863418451b27130bb4300ac1890ff806c12.tar.gz
binutils-a7067863418451b27130bb4300ac1890ff806c12.tar.bz2
gdb: Check for not allocated/associated values during array slicing
When extracting an array slice we should give up if the array is not-allocated or not-associated. For Fortran, at least in gfortran compiled code, the upper and lower bounds are undefined if the array is not allocated or not associated, in which case performing checks against these bounds will result in undefined behaviour. Better then to throw an error if we try to slice such an array. This changes the error message that the user will receive in these cases (if they got an error message before). Previously they may have gotten "slice out of range" now they'll get "array not allocated" or "array not associated". gdb/ChangeLog: * valops.c (value_slice): Check for not allocated or not associated values. gdb/testsuite/ChangeLog: * gdb.fortran/vla-sizeof.exp: Update expected results.
Diffstat (limited to 'gdb/valops.c')
-rw-r--r--gdb/valops.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/gdb/valops.c b/gdb/valops.c
index fd92a4d..cbf2ecc 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3801,6 +3801,11 @@ value_slice (struct value *array, int lowbound, int length)
&& TYPE_CODE (array_type) != TYPE_CODE_STRING)
error (_("cannot take slice of non-array"));
+ if (type_not_allocated (array_type))
+ error (_("array not allocated"));
+ if (type_not_associated (array_type))
+ error (_("array not associated"));
+
range_type = TYPE_INDEX_TYPE (array_type);
if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
error (_("slice from bad array or bitstring"));