aboutsummaryrefslogtreecommitdiff
path: root/gdb/valops.c
diff options
context:
space:
mode:
authorPedro Alves <pedro@palves.net>2021-07-15 10:47:56 +0100
committerPedro Alves <pedro@palves.net>2021-07-15 15:10:59 +0100
commit50991aaf22b03a9925ae37155f16bc8257f95242 (patch)
treedb0d641ebab1211d0f79c5dc00062c0708ad5b60 /gdb/valops.c
parent67ea24cb99efcd50d8acb6ce3e3ffbd8c97f0829 (diff)
downloadbinutils-users/palves/value_string.zip
binutils-users/palves/value_string.tar.gz
binutils-users/palves/value_string.tar.bz2
Change-Id: I79ef914087dbf85e1cbc19263843a6034383afe7
Diffstat (limited to 'gdb/valops.c')
-rw-r--r--gdb/valops.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/gdb/valops.c b/gdb/valops.c
index f67612e..161b869 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1754,12 +1754,15 @@ value_cstring (const char *ptr, ssize_t len, struct type *char_type)
{
struct value *val;
int lowbound = current_language->string_lower_bound ();
- ssize_t highbound = len / TYPE_LENGTH (char_type);
+ ssize_t highbound = len + 1;
struct type *stringtype
= lookup_array_range_type (char_type, lowbound, highbound + lowbound - 1);
val = allocate_value (stringtype);
- memcpy (value_contents_raw (val), ptr, len);
+ memcpy (value_contents_raw (val), ptr, len * TYPE_LENGTH (char_type));
+ /* Write the terminating character. */
+ memset (value_contents_raw (val) + len * TYPE_LENGTH (char_type),
+ 0, TYPE_LENGTH (char_type));
return val;
}