This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] c++/11734
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Cc: Keith Seitz <keiths at redhat dot com>
- Date: Tue, 22 Jun 2010 10:45:22 +0100
- Subject: Re: [RFA] c++/11734
- References: <4C20103B.1080906@redhat.com>
No comments on the idea of the patch itself, just
a quick comment on something that made me stop for a second
while skimming your patch:
On Tuesday 22 June 2010 02:22:03, Keith Seitz wrote:
> + new = alloca (strlen (name));
Note that alloca in a loop in general isn't a good idea. The
stack memory added in each iteration is only released on function
exit, not on each iteration, so you're prone to stack overflow
given enough loops. It looks like `name' is invariant in
this loop, so you could for example, move the `new' declaration
out of the loop, initialized as NULL, and allocate it only once
on first need.
> + memcpy (new, name, paren - name);
> + new[name - paren] = '\0';
--
Pedro Alves