Fix ASN.1 template compiler bug and add test cases more likely to trip on similar (structure size/type) errors

Signed-off-by: Roland C. Dowdeswell <elric@imrryr.org>
This commit is contained in:
Viktor Dukhovni
2012-05-27 08:07:28 +00:00
committed by Roland C. Dowdeswell
parent 0fad20a7ce
commit 5e081aa4a6
4 changed files with 350 additions and 4 deletions

View File

@@ -808,7 +808,9 @@ generate_template_type(const char *varname,
{
struct tlist *tl;
const char *d;
char *szt = NULL;
int have_ellipsis = 0;
int n;
tl = tlist_new(varname);
@@ -823,13 +825,24 @@ generate_template_type(const char *varname,
}
}
if (isstruct)
if (name)
n = asprintf(&szt, "struct %s_%s", basetype, name);
else
n = asprintf(&szt, "struct %s", basetype);
else
n = asprintf(&szt, "%s", basetype);
if (n < 0 || szt == NULL)
errx(1, "malloc");
if (ASN1_TAILQ_EMPTY(&tl->template) && compact_tag(type)->type != TNull)
errx(1, "Tag %s...%s with no content ?", basetype, name ? name : "");
tlist_header(tl, "{ 0%s%s, sizeof(%s%s), ((void *)%lu) }",
tlist_header(tl, "{ 0%s%s, sizeof(%s), ((void *)%lu) }",
(symname && preserve_type(symname)) ? "|A1_HF_PRESERVE" : "",
have_ellipsis ? "|A1_HF_ELLIPSIS" : "",
isstruct ? "struct " : "", basetype, tlist_count(tl));
have_ellipsis ? "|A1_HF_ELLIPSIS" : "", szt, tlist_count(tl));
free(szt);
d = tlist_find_dup(tl);
if (d) {