2009-09-21 Phil Muldoon <pmuldoon@redhat.com>

* python/py-value.c (valpy_getitem): Test value before allowing
	subscript operation.

2009-09-21  Phil Muldoon <pmuldoon@redhat.com>

	* gdb.python/py-value.exp (test_subscript_regression): New
	function.  Test for invalid subscripts.
	* gdb.python/py-value.c (main): Add test array, and pointer to it.
	(ptr_ref): New function.
This commit is contained in:
Phil Muldoon
2009-09-21 09:32:28 +00:00
parent cdfbdf303d
commit 2e4d963fb2
5 changed files with 113 additions and 1 deletions

View File

@ -324,7 +324,18 @@ valpy_getitem (PyObject *self, PyObject *key)
type. */
struct value *idx = convert_value_from_python (key);
if (idx != NULL)
res_val = value_subscript (tmp, value_as_long (idx));
{
/* Check the value's type is something that can be accessed via
a subscript. */
struct type *type;
tmp = coerce_ref (tmp);
type = check_typedef (value_type (tmp));
if (TYPE_CODE (type) != TYPE_CODE_ARRAY
&& TYPE_CODE (type) != TYPE_CODE_PTR)
error( _("Cannot subscript requested type"));
else
res_val = value_subscript (tmp, value_as_long (idx));
}
}
}