catch error from as.*printf
This commit is contained in:
@@ -46,7 +46,7 @@ static int
|
||||
doit(const char *fn)
|
||||
{
|
||||
char buf[2048];
|
||||
char *fnout;
|
||||
char *fnout = NULL;
|
||||
const char *bname;
|
||||
unsigned long line = 0;
|
||||
FILE *f, *fout;
|
||||
@@ -62,8 +62,7 @@ doit(const char *fn)
|
||||
else
|
||||
bname = fn;
|
||||
|
||||
asprintf(&fnout, "%s.out", bname);
|
||||
if (fnout == NULL)
|
||||
if (asprintf(&fnout, "%s.out", bname) < 0 || fnout == NULL)
|
||||
errx(1, "malloc");
|
||||
|
||||
fout = fopen(fnout, "w");
|
||||
|
@@ -1007,7 +1007,8 @@ static void fix_labels1(struct memhead *members, const char *prefix)
|
||||
if(members == NULL)
|
||||
return;
|
||||
ASN1_TAILQ_FOREACH(m, members, members) {
|
||||
asprintf(&m->label, "%s_%s", prefix, m->gen_name);
|
||||
if (asprintf(&m->label, "%s_%s", prefix, m->gen_name) < 0)
|
||||
errx(1, "malloc");
|
||||
if (m->label == NULL)
|
||||
errx(1, "malloc");
|
||||
if(m->type != NULL)
|
||||
@@ -1024,9 +1025,8 @@ static void fix_labels2(Type *t, const char *prefix)
|
||||
static void
|
||||
fix_labels(Symbol *s)
|
||||
{
|
||||
char *p;
|
||||
asprintf(&p, "choice_%s", s->gen_name);
|
||||
if (p == NULL)
|
||||
char *p = NULL;
|
||||
if (asprintf(&p, "choice_%s", s->gen_name) < 0 || p == NULL)
|
||||
errx(1, "malloc");
|
||||
fix_labels2(s->type, p);
|
||||
free(p);
|
||||
|
@@ -77,7 +77,8 @@ test_integer (void)
|
||||
|
||||
for (i = 0; i < ntests; ++i) {
|
||||
tests[i].val = &values[i];
|
||||
asprintf (&tests[i].name, "integer %d", values[i]);
|
||||
if (asprintf (&tests[i].name, "integer %d", values[i]) < 0)
|
||||
errx(1, "malloc");
|
||||
if (tests[i].name == NULL)
|
||||
errx(1, "malloc");
|
||||
}
|
||||
@@ -200,7 +201,8 @@ test_unsigned (void)
|
||||
|
||||
for (i = 0; i < ntests; ++i) {
|
||||
tests[i].val = &values[i];
|
||||
asprintf (&tests[i].name, "unsigned %u", values[i]);
|
||||
if (asprintf (&tests[i].name, "unsigned %u", values[i]) < 0)
|
||||
errx(1, "malloc");
|
||||
if (tests[i].name == NULL)
|
||||
errx(1, "malloc");
|
||||
}
|
||||
@@ -241,7 +243,8 @@ test_octet_string (void)
|
||||
int ret;
|
||||
|
||||
tests[0].val = &s1;
|
||||
asprintf (&tests[0].name, "a octet string");
|
||||
if (asprintf (&tests[0].name, "a octet string") < 0)
|
||||
errx(1, "malloc");
|
||||
if (tests[0].name == NULL)
|
||||
errx(1, "malloc");
|
||||
|
||||
@@ -282,11 +285,13 @@ test_bmp_string (void)
|
||||
int ret;
|
||||
|
||||
tests[0].val = &s1;
|
||||
asprintf (&tests[0].name, "a bmp string");
|
||||
if (asprintf (&tests[0].name, "a bmp string") < 0)
|
||||
errx(1, "malloc");
|
||||
if (tests[0].name == NULL)
|
||||
errx(1, "malloc");
|
||||
tests[1].val = &s2;
|
||||
asprintf (&tests[1].name, "second bmp string");
|
||||
if (asprintf (&tests[1].name, "second bmp string") < 0)
|
||||
errx(1, "malloc");
|
||||
if (tests[1].name == NULL)
|
||||
errx(1, "malloc");
|
||||
|
||||
@@ -328,11 +333,13 @@ test_universal_string (void)
|
||||
int ret;
|
||||
|
||||
tests[0].val = &s1;
|
||||
asprintf (&tests[0].name, "a universal string");
|
||||
if (asprintf (&tests[0].name, "a universal string") < 0)
|
||||
errx(1, "malloc");
|
||||
if (tests[0].name == NULL)
|
||||
errx(1, "malloc");
|
||||
tests[1].val = &s2;
|
||||
asprintf (&tests[1].name, "second universal string");
|
||||
if (asprintf (&tests[1].name, "second universal string") < 0)
|
||||
errx(1, "malloc");
|
||||
if (tests[1].name == NULL)
|
||||
errx(1, "malloc");
|
||||
|
||||
@@ -368,7 +375,8 @@ test_general_string (void)
|
||||
int ret, ntests = sizeof(tests) / sizeof(*tests);
|
||||
|
||||
tests[0].val = &s1;
|
||||
asprintf (&tests[0].name, "the string \"%s\"", s1);
|
||||
if (asprintf (&tests[0].name, "the string \"%s\"", s1) < 0)
|
||||
errx(1, "malloc");
|
||||
if (tests[0].name == NULL)
|
||||
errx(1, "malloc");
|
||||
|
||||
@@ -405,7 +413,8 @@ test_generalized_time (void)
|
||||
|
||||
for (i = 0; i < ntests; ++i) {
|
||||
tests[i].val = &values[i];
|
||||
asprintf (&tests[i].name, "time %d", (int)values[i]);
|
||||
if (asprintf (&tests[i].name, "time %d", (int)values[i]) < 0)
|
||||
errx(1, "malloc");
|
||||
if (tests[i].name == NULL)
|
||||
errx(1, "malloc");
|
||||
}
|
||||
@@ -453,7 +462,8 @@ test_oid (void)
|
||||
|
||||
for (i = 0; i < ntests; ++i) {
|
||||
tests[i].val = &values[i];
|
||||
asprintf (&tests[i].name, "oid %d", i);
|
||||
if (asprintf (&tests[i].name, "oid %d", i) < 0)
|
||||
errx(1, "malloc");
|
||||
if (tests[i].name == NULL)
|
||||
errx(1, "malloc");
|
||||
}
|
||||
@@ -490,7 +500,8 @@ test_bit_string (void)
|
||||
|
||||
for (i = 0; i < ntests; ++i) {
|
||||
tests[i].val = &values[i];
|
||||
asprintf (&tests[i].name, "bit_string %d", i);
|
||||
if (asprintf (&tests[i].name, "bit_string %d", i) < 0)
|
||||
errx(1, "malloc");
|
||||
if (tests[i].name == NULL)
|
||||
errx(1, "malloc");
|
||||
}
|
||||
@@ -542,7 +553,8 @@ test_heim_integer (void)
|
||||
|
||||
for (i = 0; i < ntests; ++i) {
|
||||
tests[i].val = &values[i];
|
||||
asprintf (&tests[i].name, "heim_integer %d", i);
|
||||
if (asprintf (&tests[i].name, "heim_integer %d", i) < 0)
|
||||
errx(1, "malloc");
|
||||
if (tests[i].name == NULL)
|
||||
errx(1, "malloc");
|
||||
}
|
||||
@@ -592,7 +604,8 @@ test_boolean (void)
|
||||
|
||||
for (i = 0; i < ntests; ++i) {
|
||||
tests[i].val = &values[i];
|
||||
asprintf (&tests[i].name, "heim_boolean %d", i);
|
||||
if (asprintf (&tests[i].name, "heim_boolean %d", i) < 0)
|
||||
errx(1, "malloc");
|
||||
if (tests[i].name == NULL)
|
||||
errx(1, "malloc");
|
||||
}
|
||||
|
@@ -126,23 +126,20 @@ init_generate (const char *filename, const char *base)
|
||||
}
|
||||
|
||||
/* public header file */
|
||||
asprintf(&header, "%s.h", headerbase);
|
||||
if (header == NULL)
|
||||
if (asprintf(&header, "%s.h", headerbase) < 0 || header == NULL)
|
||||
errx(1, "malloc");
|
||||
asprintf(&fn, "%s.hx", headerbase);
|
||||
if (fn == NULL)
|
||||
if (asprintf(&fn, "%s.hx", headerbase) < 0 || fn == NULL)
|
||||
errx(1, "malloc");
|
||||
headerfile = fopen (fn, "w");
|
||||
if (headerfile == NULL)
|
||||
err (1, "open %s", fn);
|
||||
free(fn);
|
||||
fn = NULL;
|
||||
|
||||
/* private header file */
|
||||
asprintf(&privheader, "%s-priv.h", headerbase);
|
||||
if (privheader == NULL)
|
||||
if (asprintf(&privheader, "%s-priv.h", headerbase) < 0 || privheader == NULL)
|
||||
errx(1, "malloc");
|
||||
asprintf(&fn, "%s-priv.hx", headerbase);
|
||||
if (fn == NULL)
|
||||
if (asprintf(&fn, "%s-priv.hx", headerbase) < 0 || fn == NULL)
|
||||
errx(1, "malloc");
|
||||
privheaderfile = fopen (fn, "w");
|
||||
if (privheaderfile == NULL)
|
||||
@@ -150,10 +147,8 @@ init_generate (const char *filename, const char *base)
|
||||
free(fn);
|
||||
|
||||
/* template file */
|
||||
asprintf(&template, "%s-template.c", headerbase);
|
||||
if (template == NULL)
|
||||
if (asprintf(&template, "%s-template.c", headerbase) < 0 || template == NULL)
|
||||
errx(1, "malloc");
|
||||
|
||||
fprintf (headerfile,
|
||||
"/* Generated from %s */\n"
|
||||
"/* Do not edit */\n\n",
|
||||
|
@@ -110,14 +110,16 @@ copy_type (const char *from, const char *to, const Type *t, int preserve)
|
||||
if(t->type == TChoice)
|
||||
fprintf(codefile, "case %s:\n", m->label);
|
||||
|
||||
asprintf (&fs, "%s(%s)->%s%s",
|
||||
if (asprintf (&fs, "%s(%s)->%s%s",
|
||||
m->optional ? "" : "&", from,
|
||||
t->type == TChoice ? "u." : "", m->gen_name);
|
||||
t->type == TChoice ? "u." : "", m->gen_name) < 0)
|
||||
errx(1, "malloc");
|
||||
if (fs == NULL)
|
||||
errx(1, "malloc");
|
||||
asprintf (&ts, "%s(%s)->%s%s",
|
||||
if (asprintf (&ts, "%s(%s)->%s%s",
|
||||
m->optional ? "" : "&", to,
|
||||
t->type == TChoice ? "u." : "", m->gen_name);
|
||||
t->type == TChoice ? "u." : "", m->gen_name) < 0)
|
||||
errx(1, "malloc");
|
||||
if (ts == NULL)
|
||||
errx(1, "malloc");
|
||||
if(m->optional){
|
||||
@@ -155,8 +157,7 @@ copy_type (const char *from, const char *to, const Type *t, int preserve)
|
||||
}
|
||||
case TSetOf:
|
||||
case TSequenceOf: {
|
||||
char *f;
|
||||
char *T;
|
||||
char *f = NULL, *T = NULL;
|
||||
|
||||
fprintf (codefile, "if(((%s)->val = "
|
||||
"malloc((%s)->len * sizeof(*(%s)->val))) == NULL && (%s)->len != 0)\n",
|
||||
@@ -166,10 +167,12 @@ copy_type (const char *from, const char *to, const Type *t, int preserve)
|
||||
fprintf(codefile,
|
||||
"for((%s)->len = 0; (%s)->len < (%s)->len; (%s)->len++){\n",
|
||||
to, to, from, to);
|
||||
asprintf(&f, "&(%s)->val[(%s)->len]", from, to);
|
||||
if (asprintf(&f, "&(%s)->val[(%s)->len]", from, to) < 0)
|
||||
errx(1, "malloc");
|
||||
if (f == NULL)
|
||||
errx(1, "malloc");
|
||||
asprintf(&T, "&(%s)->val[(%s)->len]", to, to);
|
||||
if (asprintf(&T, "&(%s)->val[(%s)->len]", to, to) < 0)
|
||||
errx(1, "malloc");
|
||||
if (T == NULL)
|
||||
errx(1, "malloc");
|
||||
copy_type(f, T, t->subtype, FALSE);
|
||||
|
Reference in New Issue
Block a user