Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* PATCH: allocate namecopy on heap, not stack
@ 2005-04-29 21:38 Jim Blandy
  2005-04-29 21:39 ` Daniel Jacobowitz
  0 siblings, 1 reply; 4+ messages in thread
From: Jim Blandy @ 2005-04-29 21:38 UTC (permalink / raw)
  To: gdb-patches


Committed as obvious.

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.

Index: gdb/parse.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/parse.c,v
retrieving revision 2.105
diff -c -p -r2.105 parse.c
*** gdb/parse.c	13 Apr 2004 16:38:57 -0000	2.105
--- gdb/parse.c	28 Apr 2005 23:58:49 -0000
*************** union type_stack_elt *type_stack;
*** 89,97 ****
  int type_stack_depth, type_stack_size;
  char *lexptr;
  char *prev_lexptr;
- char *namecopy;
  int paren_depth;
  int comma_terminates;
  \f
  static int expressiondebug = 0;
  
--- 89,106 ----
  int type_stack_depth, type_stack_size;
  char *lexptr;
  char *prev_lexptr;
  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;
  \f
  static int expressiondebug = 0;
  
*************** find_template_name_end (char *p)
*** 769,776 ****
--- 778,793 ----
  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;
  }
  \f
*************** parse_exp_1 (char **stringptr, struct bl
*** 1045,1051 ****
    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 *)
--- 1062,1067 ----


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: allocate namecopy on heap, not stack
  2005-04-29 21:38 PATCH: allocate namecopy on heap, not stack Jim Blandy
@ 2005-04-29 21:39 ` Daniel Jacobowitz
  2005-04-29 22:54   ` Jim Blandy
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jacobowitz @ 2005-04-29 21:39 UTC (permalink / raw)
  To: Jim Blandy; +Cc: gdb-patches

On Fri, Apr 29, 2005 at 04:35:35PM -0500, Jim Blandy wrote:
> 
> Committed as obvious.
> 
> 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.

What prompted ths change?  Even "obvious" patches deserve an
explanation.

-- 
Daniel Jacobowitz
CodeSourcery, LLC


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: allocate namecopy on heap, not stack
  2005-04-29 21:39 ` Daniel Jacobowitz
@ 2005-04-29 22:54   ` Jim Blandy
  2005-04-29 23:56     ` Daniel Jacobowitz
  0 siblings, 1 reply; 4+ messages in thread
From: Jim Blandy @ 2005-04-29 22:54 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb-patches

Daniel Jacobowitz <drow@false.org> writes:

> On Fri, Apr 29, 2005 at 04:35:35PM -0500, Jim Blandy wrote:
> > 
> > Committed as obvious.
> > 
> > 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.
> 
> What prompted ths change?  Even "obvious" patches deserve an
> explanation.

Certainly --- did you see this?

+ 
+ /* 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;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: allocate namecopy on heap, not stack
  2005-04-29 22:54   ` Jim Blandy
@ 2005-04-29 23:56     ` Daniel Jacobowitz
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2005-04-29 23:56 UTC (permalink / raw)
  To: Jim Blandy; +Cc: gdb-patches

On Fri, Apr 29, 2005 at 05:52:18PM -0500, Jim Blandy wrote:
> Certainly --- did you see this?
> 
> + 
> + /* 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;

No, I didn't.  Thanks for explaining.

-- 
Daniel Jacobowitz
CodeSourcery, LLC


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-04-29 23:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-29 21:38 PATCH: allocate namecopy on heap, not stack Jim Blandy
2005-04-29 21:39 ` Daniel Jacobowitz
2005-04-29 22:54   ` Jim Blandy
2005-04-29 23:56     ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox