aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@sourceware.org>2012-09-14 12:46:55 +0000
committerSiddhesh Poyarekar <siddhesh@sourceware.org>2012-09-14 12:46:55 +0000
commit84c47588d0a7a8afffb338303fcb4cc527458ae4 (patch)
tree488e1672fb5b8b3eda31df6609910bc248121bf3
parentf4045bcb616769e57d65a03a751e9cf351e51804 (diff)
downloadgdb-84c47588d0a7a8afffb338303fcb4cc527458ae4.zip
gdb-84c47588d0a7a8afffb338303fcb4cc527458ae4.tar.gz
gdb-84c47588d0a7a8afffb338303fcb4cc527458ae4.tar.bz2
* valarith.c (value_concat): Replace unsafe ALLOCA with
XMALLOC/XFREE.
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/valarith.c12
2 files changed, 15 insertions, 2 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ecf7d22..beaa8c2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2012-09-14 Siddhesh Poyarekar <siddhesh@redhat.com>
+
+ * valarith.c (value_concat): Replace unsafe ALLOCA with
+ XMALLOC/XFREE.
+
2012-09-14 Pedro Alves <palves@redhat.com>
* gdb.1 (SEE ALSO): Expand pointer to GDB's Texinfo manual.
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 6858d2b..c457f4a 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -668,9 +668,12 @@ value_concat (struct value *arg1, struct value *arg2)
if (TYPE_CODE (type2) == TYPE_CODE_STRING
|| TYPE_CODE (type2) == TYPE_CODE_CHAR)
{
+ struct cleanup *back_to;
+
count = longest_to_int (value_as_long (inval1));
inval2len = TYPE_LENGTH (type2);
- ptr = (char *) alloca (count * inval2len);
+ ptr = (char *) xmalloc (count * inval2len);
+ back_to = make_cleanup (xfree, ptr);
if (TYPE_CODE (type2) == TYPE_CODE_CHAR)
{
char_type = type2;
@@ -693,6 +696,7 @@ value_concat (struct value *arg1, struct value *arg2)
}
}
outval = value_string (ptr, count * inval2len, char_type);
+ do_cleanups (back_to);
}
else if (TYPE_CODE (type2) == TYPE_CODE_BOOL)
{
@@ -706,6 +710,8 @@ value_concat (struct value *arg1, struct value *arg2)
else if (TYPE_CODE (type1) == TYPE_CODE_STRING
|| TYPE_CODE (type1) == TYPE_CODE_CHAR)
{
+ struct cleanup *back_to;
+
/* We have two character strings to concatenate. */
if (TYPE_CODE (type2) != TYPE_CODE_STRING
&& TYPE_CODE (type2) != TYPE_CODE_CHAR)
@@ -714,7 +720,8 @@ value_concat (struct value *arg1, struct value *arg2)
}
inval1len = TYPE_LENGTH (type1);
inval2len = TYPE_LENGTH (type2);
- ptr = (char *) alloca (inval1len + inval2len);
+ ptr = (char *) xmalloc (inval1len + inval2len);
+ back_to = make_cleanup (xfree, ptr);
if (TYPE_CODE (type1) == TYPE_CODE_CHAR)
{
char_type = type1;
@@ -737,6 +744,7 @@ value_concat (struct value *arg1, struct value *arg2)
memcpy (ptr + inval1len, value_contents (inval2), inval2len);
}
outval = value_string (ptr, inval1len + inval2len, char_type);
+ do_cleanups (back_to);
}
else if (TYPE_CODE (type1) == TYPE_CODE_BOOL)
{