diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2021-10-04 20:47:06 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2021-10-25 14:51:44 -0400 |
commit | 50888e42dcd32b30e1144c0aa6d1c1490da45cd9 (patch) | |
tree | 72fad89d67057ecb53f26bac0464542829053e3e /gdb/opencl-lang.c | |
parent | d9f82e931394efed68858eb7c7bb5832ad888482 (diff) | |
download | gdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.zip gdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.tar.gz gdb-50888e42dcd32b30e1144c0aa6d1c1490da45cd9.tar.bz2 |
gdb: change functions returning value contents to use gdb::array_view
The bug fixed by this [1] patch was caused by an out-of-bounds access to
a value's content. The code gets the value's content (just a pointer)
and then indexes it with a non-sensical index.
This made me think of changing functions that return value contents to
return array_views instead of a plain pointer. This has the advantage
that when GDB is built with _GLIBCXX_DEBUG, accesses to the array_view
are checked, making bugs more apparent / easier to find.
This patch changes the return types of these functions, and updates
callers to call .data() on the result, meaning it's not changing
anything in practice. Additional work will be needed (which can be done
little by little) to make callers propagate the use of array_view and
reap the benefits.
[1] https://sourceware.org/pipermail/gdb-patches/2021-September/182306.html
Change-Id: I5151f888f169e1c36abe2cbc57620110673816f3
Diffstat (limited to 'gdb/opencl-lang.c')
-rw-r--r-- | gdb/opencl-lang.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c index b279674..437f27f 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -139,8 +139,8 @@ lval_func_read (struct value *v) gdb_assert (n <= c->n); for (i = offset; i < n; i++) - memcpy (value_contents_raw (v) + j++ * elsize, - value_contents (c->val) + c->indices[i] * elsize, + memcpy (value_contents_raw (v).data () + j++ * elsize, + value_contents (c->val).data () + c->indices[i] * elsize, elsize); } @@ -179,8 +179,8 @@ lval_func_write (struct value *v, struct value *fromval) struct value *from_elm_val = allocate_value (eltype); struct value *to_elm_val = value_subscript (c->val, c->indices[i]); - memcpy (value_contents_writeable (from_elm_val), - value_contents (fromval) + j++ * elsize, + memcpy (value_contents_writeable (from_elm_val).data (), + value_contents (fromval).data () + j++ * elsize, elsize); value_assign (to_elm_val, from_elm_val); } @@ -315,9 +315,9 @@ create_value (struct gdbarch *gdbarch, struct value *val, enum noside noside, /* Copy src val contents into the destination value. */ for (i = 0; i < n; i++) - memcpy (value_contents_writeable (ret) + memcpy (value_contents_writeable (ret).data () + (i * TYPE_LENGTH (elm_type)), - value_contents (val) + value_contents (val).data () + (indices[i] * TYPE_LENGTH (elm_type)), TYPE_LENGTH (elm_type)); } @@ -473,7 +473,8 @@ opencl_logical_not (struct type *expect_type, struct expression *exp, value of its operand compares unequal to 0, and -1 (i.e. all bits set) if the value of its operand compares equal to 0. */ int tmp = value_logical_not (value_subscript (arg, i)) ? -1 : 0; - memset (value_contents_writeable (ret) + i * TYPE_LENGTH (eltype), + memset ((value_contents_writeable (ret).data () + + i * TYPE_LENGTH (eltype)), tmp, TYPE_LENGTH (eltype)); } } @@ -573,7 +574,8 @@ vector_relop (struct expression *exp, struct value *val1, struct value *val2, if the specified relation is true. */ int tmp = scalar_relop (value_subscript (val1, i), value_subscript (val2, i), op) ? -1 : 0; - memset (value_contents_writeable (ret) + i * TYPE_LENGTH (eltype1), + memset ((value_contents_writeable (ret).data () + + i * TYPE_LENGTH (eltype1)), tmp, TYPE_LENGTH (eltype1)); } @@ -836,8 +838,8 @@ Cannot perform conditional operation on vectors with different sizes")); { tmp = value_logical_not (value_subscript (arg1, i)) ? value_subscript (arg3, i) : value_subscript (arg2, i); - memcpy (value_contents_writeable (ret) + - i * TYPE_LENGTH (eltype2), value_contents_all (tmp), + memcpy (value_contents_writeable (ret).data () + + i * TYPE_LENGTH (eltype2), value_contents_all (tmp).data (), TYPE_LENGTH (eltype2)); } |