From c2bffd0a9793be8a23ab719557756b2a2ce2c3b5 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Wed, 4 Nov 2020 11:02:05 +0000 Subject: Merge elftoolchain r3877 (by jkoshy): Incorporate fixes from Dimitry Andric: - Use a BUFFER_GROW() macro to avoid rounding errors in capacity calculations. - Fix a bug introduced in [r3531]. - Fix handling of nested template parameters. Ticket: #581 This should fix a number of assertions on elftoolchain's cxxfilt, and allow it to correctly demangle several names that it could not handle before. Obtained from: https://sourceforge.net/p/elftoolchain/code/3877/ PR: 250702 MFC after: 3 days --- contrib/elftoolchain/libelftc/_libelftc.h | 1 + contrib/elftoolchain/libelftc/libelftc_dem_gnu3.c | 10 +++++----- contrib/elftoolchain/libelftc/libelftc_vstr.c | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'contrib') diff --git a/contrib/elftoolchain/libelftc/_libelftc.h b/contrib/elftoolchain/libelftc/_libelftc.h index a56e29ee4a5b..96a13a1a9509 100644 --- a/contrib/elftoolchain/libelftc/_libelftc.h +++ b/contrib/elftoolchain/libelftc/_libelftc.h @@ -56,6 +56,7 @@ struct vector_str { }; #define BUFFER_GROWFACTOR 1.618 +#define BUFFER_GROW(x) (((x)+0.5)*BUFFER_GROWFACTOR) #define ELFTC_FAILURE 0 #define ELFTC_ISDIGIT(C) (isdigit((C) & 0xFF)) diff --git a/contrib/elftoolchain/libelftc/libelftc_dem_gnu3.c b/contrib/elftoolchain/libelftc/libelftc_dem_gnu3.c index fa9fdeb83ea6..a84ca2649497 100644 --- a/contrib/elftoolchain/libelftc/libelftc_dem_gnu3.c +++ b/contrib/elftoolchain/libelftc/libelftc_dem_gnu3.c @@ -2135,10 +2135,10 @@ cpp_demangle_read_sname(struct cpp_demangle_data *ddata) if (err == 0) return (0); - assert(ddata->output.size > 0); + assert(ddata->cur_output->size > 0); if (vector_read_cmd_find(&ddata->cmd, READ_TMPL) == NULL) ddata->last_sname = - ddata->output.container[ddata->output.size - 1]; + ddata->cur_output->container[ddata->output.size - 1]; ddata->cur += len; @@ -2421,7 +2421,7 @@ cpp_demangle_read_tmpl_args(struct cpp_demangle_data *ddata) return (0); limit = 0; - v = &ddata->output; + v = ddata->cur_output; for (;;) { idx = v->size; if (!cpp_demangle_read_tmpl_arg(ddata)) @@ -3909,7 +3909,7 @@ vector_read_cmd_push(struct vector_read_cmd *v, enum read_cmd cmd, void *data) return (0); if (v->size == v->capacity) { - tmp_cap = v->capacity * BUFFER_GROWFACTOR; + tmp_cap = BUFFER_GROW(v->capacity); if ((tmp_r_ctn = malloc(sizeof(*tmp_r_ctn) * tmp_cap)) == NULL) return (0); for (i = 0; i < v->size; ++i) @@ -3974,7 +3974,7 @@ vector_type_qualifier_push(struct vector_type_qualifier *v, return (0); if (v->size == v->capacity) { - tmp_cap = v->capacity * BUFFER_GROWFACTOR; + tmp_cap = BUFFER_GROW(v->capacity); if ((tmp_ctn = malloc(sizeof(enum type_qualifier) * tmp_cap)) == NULL) return (0); diff --git a/contrib/elftoolchain/libelftc/libelftc_vstr.c b/contrib/elftoolchain/libelftc/libelftc_vstr.c index 934b5dba4c96..af969c1cf831 100644 --- a/contrib/elftoolchain/libelftc/libelftc_vstr.c +++ b/contrib/elftoolchain/libelftc/libelftc_vstr.c @@ -152,7 +152,7 @@ vector_str_grow(struct vector_str *v) assert(v->capacity > 0); - tmp_cap = v->capacity * BUFFER_GROWFACTOR; + tmp_cap = BUFFER_GROW(v->capacity); assert(tmp_cap > v->capacity); @@ -253,7 +253,7 @@ vector_str_push_vector_head(struct vector_str *dst, struct vector_str *org) if (dst == NULL || org == NULL) return (false); - tmp_cap = (dst->size + org->size) * BUFFER_GROWFACTOR; + tmp_cap = BUFFER_GROW(dst->size + org->size); if ((tmp_ctn = malloc(sizeof(char *) * tmp_cap)) == NULL) return (false); @@ -293,7 +293,7 @@ vector_str_push_vector(struct vector_str *dst, struct vector_str *org) if (dst == NULL || org == NULL) return (false); - tmp_cap = (dst->size + org->size) * BUFFER_GROWFACTOR; + tmp_cap = BUFFER_GROW(dst->size + org->size); if ((tmp_ctn = malloc(sizeof(char *) * tmp_cap)) == NULL) return (false); -- cgit v1.2.3