This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Force array coercion in c_get_string
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>> The actual patch is somewhat more
>> complicated than you might think, because the caller can request more
>> array elements than the type allows. This is normal when the type is
>> using the C struct hack.
Pedro> Which test exposes this issue?
>From py-value.exp:
# Test fetching a string longer than its declared (in C) size.
# PR 16286
gdb_py_test_silent_cmd "python xstr = gdb.parse_and_eval('xstr')" "get xstr" 1
gdb_test "python print(xstr\['text'\].string (length = xstr\['length'\]))" "x{100}" \
"read string beyond declared size"
Pedro> I'm a bit confused here. If we ever coerce an array and then read more
Pedro> elements than the type allows, won't we be reading garbage passed the
Pedro> coerced array elements?
In the case where we want to read past the array limit, c_get_string
will take the second branch, which does an explicit read_string.
Tom