This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] Fix DEMANGLE_COMPONENT_TEMPLATE_ARGLIST demangling (PR other/43838)
- From: Ian Lance Taylor <iant at google dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Jason Merrill <jason at redhat dot com>, gcc-patches at gcc dot gnu dot org, binutils at sourceware dot org
- Date: Wed, 09 Jun 2010 13:03:08 -0700
- Subject: Re: [PATCH] Fix DEMANGLE_COMPONENT_TEMPLATE_ARGLIST demangling (PR other/43838)
- References: <20100609191454.GG10293@tyan-ft48-01.lab.bos.redhat.com>
Jakub Jelinek <jakub@redhat.com> writes:
> 2010-06-09 Jakub Jelinek <jakub@redhat.com>
>
> PR other/43838
> * cp-demangle.c (struct d_print_info): Add flush_count field.
> (d_print_init): Initialize it to 0.
> (d_print_flush): Increment it.
> (d_print_comp): If needed flush before appending ", ". Only
> decrement dpi->len if no flushes happened during the recursive
> call.
> * testsuite/demangle-expected: Add a test for this.
> @@ -4047,12 +4051,18 @@ d_print_comp (struct d_print_info *dpi,
> if (d_right (dc) != NULL)
> {
> size_t len;
> + unsigned long int flush_count;
> + /* Make sure ", " isn't flushed by d_append_string, otherwise
> + dpi->len -= 2 wouldn't work. */
> + if (dpi->len >= sizeof (dpi->buf) - 2)
> + d_print_flush (dpi);
> d_append_string (dpi, ", ");
> len = dpi->len;
> + flush_count = dpi->flush_count;
> d_print_comp (dpi, d_right (dc));
> /* If that didn't print anything (which can happen with empty
> template argument packs), remove the comma and space. */
> - if (dpi->len == len)
> + if (dpi->flush_count == flush_count && dpi->len == len)
> dpi->len -= 2;
> }
I suppose this is OK, but it seems simpler and cleaner to just check
whether the d_print_comp will print anything before appending the
comma. It seems like it should work to do
struct demangle_component *right = d_right (dc);
if (right != NULL && (d_left (right) != NULL || d_right (right) != NULL))
{
d_append_string (dpi, ", ");
d_print_comp (dpi, right);
}
Ian