Fix off-by-one bug calling value_cstring
Daniel Colascione
dancol@dancol.org
Tue Oct 7 05:25:00 GMT 2014
Sometimes we create strings that aren't NUL-terminated.
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 185b38e..0953e0d 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -660,7 +660,7 @@ evaluate_subexp_c (struct type *expect_type, struct
expression *exp,
else if ((dest_type & C_CHAR) != 0)
result = allocate_value (type);
else
- result = value_cstring ("", 0, type);
+ result = value_cstring ("", 1, type);
do_cleanups (cleanup);
return result;
}
diff --git a/gdb/guile/scm-math.c b/gdb/guile/scm-math.c
index e05f99e..d533bf6 100644
--- a/gdb/guile/scm-math.c
+++ b/gdb/guile/scm-math.c
@@ -827,7 +827,7 @@ vlscm_convert_typed_value_from_scheme (const char
*func_name,
{
cleanup = make_cleanup (xfree, s);
value
- = value_cstring (s, len,
+ = value_cstring (s, len + 1,
language_string_char_type (language,
gdbarch));
do_cleanups (cleanup);
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 0cefd4f..ca20921 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1601,7 +1601,7 @@ convert_value_from_python (PyObject *obj)
struct cleanup *old;
old = make_cleanup (xfree, s);
- value = value_cstring (s, strlen (s), builtin_type_pychar);
+ value = value_cstring (s, strlen (s) + 1, builtin_type_pychar);
do_cleanups (old);
}
}
diff --git a/gdb/value.c b/gdb/value.c
index fdc8858d..0198e03 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2147,7 +2147,7 @@ value_of_internalvar (struct gdbarch *gdbarch,
struct internalvar *var)
break;
case INTERNALVAR_STRING:
- val = value_cstring (var->u.string, strlen (var->u.string),
+ val = value_cstring (var->u.string, strlen (var->u.string) + 1,
builtin_type (gdbarch)->builtin_char);
break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20141007/8cf644b6/attachment.sig>
More information about the Gdb-patches
mailing list