aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorJim Blandy <jimb@codesourcery.com>2005-04-29 00:04:06 +0000
committerJim Blandy <jimb@codesourcery.com>2005-04-29 00:04:06 +0000
commit3a913e29dfa9128cc6642c0380a753e5cf4aab61 (patch)
tree2aad3320b77a77cc2ebc830fd0b1e867ed5c5548 /gdb
parent85b1c36d3172747a7587cbae0f5db46de2bffcd6 (diff)
downloadgdb-3a913e29dfa9128cc6642c0380a753e5cf4aab61.zip
gdb-3a913e29dfa9128cc6642c0380a753e5cf4aab61.tar.gz
gdb-3a913e29dfa9128cc6642c0380a753e5cf4aab61.tar.bz2
* parse.c (namecopy): Change allocation conventions.
(namecopy_size): New variable. (copy_name): Allocate namecopy using xrealloc, instead of assuming it has adequate space allocated to it. (parse_exp_1): Don't try to allocate space for namecopy here.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/parse.c20
2 files changed, 26 insertions, 2 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index bd2e99d..15ac97e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2005-04-28 Jim Blandy <jimb@redhat.com>
+
+ * parse.c (namecopy): Change allocation conventions.
+ (namecopy_size): New variable.
+ (copy_name): Allocate namecopy using xrealloc, instead of assuming
+ it has adequate space allocated to it.
+ (parse_exp_1): Don't try to allocate space for namecopy here.
+
2005-04-28 Eli Zaretskii <eliz@gnu.org>
* cli/cli-cmds.c (edit_command): If symtab->fullname is not yet
diff --git a/gdb/parse.c b/gdb/parse.c
index 0fa2459..4ec96c6 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -76,9 +76,18 @@ union type_stack_elt *type_stack;
int type_stack_depth, type_stack_size;
char *lexptr;
char *prev_lexptr;
-char *namecopy;
int paren_depth;
int comma_terminates;
+
+/* A temporary buffer for identifiers, so we can null-terminate them.
+
+ We allocate this with xrealloc. parse_exp_1 used to allocate with
+ alloca, using the size of the whole expression as a conservative
+ estimate of the space needed. However, macro expansion can
+ introduce names longer than the original expression; there's no
+ practical way to know beforehand how large that might be. */
+char *namecopy;
+size_t namecopy_size;
static int expressiondebug = 0;
static void
@@ -758,8 +767,16 @@ find_template_name_end (char *p)
char *
copy_name (struct stoken token)
{
+ /* Make sure there's enough space for the token. */
+ if (namecopy_size < token.length + 1)
+ {
+ namecopy_size = token.length + 1;
+ namecopy = xrealloc (namecopy, token.length + 1);
+ }
+
memcpy (namecopy, token.ptr, token.length);
namecopy[token.length] = 0;
+
return namecopy;
}
@@ -1044,7 +1061,6 @@ parse_exp_in_context (char **stringptr, struct block *block, int comma,
else
expression_context_block = get_selected_block (&expression_context_pc);
- namecopy = (char *) alloca (strlen (lexptr) + 1);
expout_size = 10;
expout_ptr = 0;
expout = (struct expression *)