catch error from as.*printf

This commit is contained in:
Love Hornquist Astrand
2010-05-30 15:13:44 -07:00
parent e65154c6db
commit 33b8ccccd6
2 changed files with 22 additions and 21 deletions

View File

@@ -149,10 +149,9 @@ length_type (const char *name, const Type *t,
if(t->type == TChoice) if(t->type == TChoice)
fprintf(codefile, "case %s:\n", m->label); fprintf(codefile, "case %s:\n", m->label);
asprintf (&s, "%s(%s)->%s%s", if (asprintf (&s, "%s(%s)->%s%s",
m->optional ? "" : "&", name, m->optional ? "" : "&", name,
t->type == TChoice ? "u." : "", m->gen_name); t->type == TChoice ? "u." : "", m->gen_name) < 0 || s == NULL)
if (s == NULL)
errx(1, "malloc"); errx(1, "malloc");
if (m->optional) if (m->optional)
fprintf (codefile, "if(%s)", s); fprintf (codefile, "if(%s)", s);
@@ -183,8 +182,8 @@ length_type (const char *name, const Type *t,
} }
case TSetOf: case TSetOf:
case TSequenceOf: { case TSequenceOf: {
char *n; char *n = NULL;
char *sname; char *sname = NULL;
fprintf (codefile, fprintf (codefile,
"{\n" "{\n"
@@ -196,11 +195,9 @@ length_type (const char *name, const Type *t,
fprintf (codefile, "for(i = (%s)->len - 1; i >= 0; --i){\n", name); fprintf (codefile, "for(i = (%s)->len - 1; i >= 0; --i){\n", name);
fprintf (codefile, "int %s_for_oldret = %s;\n" fprintf (codefile, "int %s_for_oldret = %s;\n"
"%s = 0;\n", tmpstr, variable, variable); "%s = 0;\n", tmpstr, variable, variable);
asprintf (&n, "&(%s)->val[i]", name); if (asprintf (&n, "&(%s)->val[i]", name) < 0 || n == NULL)
if (n == NULL)
errx(1, "malloc"); errx(1, "malloc");
asprintf (&sname, "%s_S_Of", tmpstr); if (asprintf (&sname, "%s_S_Of", tmpstr) < 0 || sname == NULL)
if (sname == NULL)
errx(1, "malloc"); errx(1, "malloc");
length_type(n, t->subtype, variable, sname); length_type(n, t->subtype, variable, sname);
fprintf (codefile, "%s += %s_for_oldret;\n", fprintf (codefile, "%s += %s_for_oldret;\n",
@@ -248,9 +245,8 @@ length_type (const char *name, const Type *t,
fprintf (codefile, "/* NULL */\n"); fprintf (codefile, "/* NULL */\n");
break; break;
case TTag:{ case TTag:{
char *tname; char *tname = NULL;
asprintf(&tname, "%s_tag", tmpstr); if (asprintf(&tname, "%s_tag", tmpstr) < 0 || tname == NULL)
if (tname == NULL)
errx(1, "malloc"); errx(1, "malloc");
length_type (name, t->subtype, variable, tname); length_type (name, t->subtype, variable, tname);
fprintf (codefile, "ret += %lu + der_length_len (ret);\n", fprintf (codefile, "ret += %lu + der_length_len (ret);\n",

View File

@@ -224,7 +224,8 @@ partial_offset(const char *basetype, const char *name, int need_offset)
char *str; char *str;
if (name == NULL || need_offset == 0) if (name == NULL || need_offset == 0)
return strdup("0"); return strdup("0");
asprintf(&str, "offsetof(struct %s, %s)", basetype, name); if (asprintf(&str, "offsetof(struct %s, %s)", basetype, name) < 0 || str == NULL)
errx(1, "malloc");
return str; return str;
} }
@@ -273,7 +274,8 @@ tlist_header(struct tlist *t, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vasprintf(&t->header, fmt, ap); if (vasprintf(&t->header, fmt, ap) < 0 || t->header == NULL)
errx(1, "malloc");
va_end(ap); va_end(ap);
} }
@@ -389,7 +391,8 @@ add_line(struct templatehead *t, const char *fmt, ...)
struct template *q = calloc(1, sizeof(*q)); struct template *q = calloc(1, sizeof(*q));
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vasprintf(&q->line, fmt, ap); if (vasprintf(&q->line, fmt, ap) < 0 || q->line == NULL)
errx(1, "malloc");
va_end(ap); va_end(ap);
ASN1_TAILQ_INSERT_TAIL(t, q, members); ASN1_TAILQ_INSERT_TAIL(t, q, members);
return q; return q;
@@ -404,10 +407,11 @@ add_line_pointer(struct templatehead *t,
{ {
struct template *q; struct template *q;
va_list ap; va_list ap;
char *tt; char *tt = NULL;
va_start(ap, ttfmt); va_start(ap, ttfmt);
vasprintf(&tt, ttfmt, ap); if (vasprintf(&tt, ttfmt, ap) < 0 || tt == NULL)
errx(1, "malloc");
va_end(ap); va_end(ap);
q = add_line(t, "{ %s, %s, asn1_%s }", tt, offset, ptr); q = add_line(t, "{ %s, %s, asn1_%s }", tt, offset, ptr);
@@ -543,7 +547,7 @@ template_members(struct templatehead *temp, const char *basetype, const char *na
struct template *q; struct template *q;
Member *m; Member *m;
size_t count = 0, i; size_t count = 0, i;
char *bname; char *bname = NULL;
FILE *f = get_code_file(); FILE *f = get_code_file();
if (ASN1_TAILQ_EMPTY(t->members)) { if (ASN1_TAILQ_EMPTY(t->members)) {
@@ -551,7 +555,8 @@ template_members(struct templatehead *temp, const char *basetype, const char *na
break; break;
} }
asprintf(&bname, "bmember_%s_%lu", name ? name : "", (unsigned long)t); if (asprintf(&bname, "bmember_%s_%lu", name ? name : "", (unsigned long)t) < 0 || bname == NULL)
errx(1, "malloc");
output_name(bname); output_name(bname);
ASN1_TAILQ_FOREACH(m, t->members, members) { ASN1_TAILQ_FOREACH(m, t->members, members) {
@@ -584,7 +589,7 @@ template_members(struct templatehead *temp, const char *basetype, const char *na
ASN1_TAILQ_FOREACH(m, t->members, members) { ASN1_TAILQ_FOREACH(m, t->members, members) {
char *newbasename = NULL; char *newbasename = NULL;
if (m->ellipsis) if (m->ellipsis)
continue; continue;