aboutsummaryrefslogtreecommitdiff
path: root/gdb/printcmd.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-10-04 20:47:06 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-10-25 14:51:44 -0400
commit50888e42dcd32b30e1144c0aa6d1c1490da45cd9 (patch)
tree72fad89d67057ecb53f26bac0464542829053e3e /gdb/printcmd.c
parentd9f82e931394efed68858eb7c7bb5832ad888482 (diff)
downloadgdb-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/printcmd.c')
-rw-r--r--gdb/printcmd.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 2fe3f4b..03abd75 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2447,7 +2447,7 @@ printf_c_string (struct ui_file *stream, const char *format,
null terminated) to be printed without problems. */
gdb_byte *tem_str = (gdb_byte *) alloca (len + 1);
- memcpy (tem_str, value_contents (value), len);
+ memcpy (tem_str, value_contents (value).data (), len);
tem_str [len] = 0;
str = tem_str;
}
@@ -2511,7 +2511,7 @@ printf_wide_c_string (struct ui_file *stream, const char *format,
if (VALUE_LVAL (value) == lval_internalvar
&& c_is_string_type_p (value_type (value)))
{
- str = value_contents (value);
+ str = value_contents (value).data ();
len = TYPE_LENGTH (value_type (value));
}
else
@@ -2620,14 +2620,15 @@ printf_floating (struct ui_file *stream, const char *format,
{
param_type = float_type_from_length (param_type);
if (param_type != value_type (value))
- value = value_from_contents (param_type, value_contents (value));
+ value = value_from_contents (param_type,
+ value_contents (value).data ());
}
value = value_cast (fmt_type, value);
/* Convert the value to a string and print it. */
std::string str
- = target_float_to_string (value_contents (value), fmt_type, format);
+ = target_float_to_string (value_contents (value).data (), fmt_type, format);
fputs_filtered (str.c_str (), stream);
}
@@ -2788,7 +2789,7 @@ ui_printf (const char *arg, struct ui_file *stream)
|| valtype->code () != TYPE_CODE_INT)
error (_("expected wchar_t argument for %%lc"));
- bytes = value_contents (val_args[i]);
+ bytes = value_contents (val_args[i]).data ();
auto_obstack output;