(generate_type_decode): zero the data at the beginning of the

generated function, and add a label `fail' that the code jumps to in
case of errors that frees all allocated data


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@9667 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
2001-02-10 18:14:38 +00:00
parent c6be2d0aad
commit 6f980743fb

View File

@@ -281,7 +281,7 @@ generate_type_decode (const Symbol *s)
s->gen_name, s->gen_name);
fprintf (codefile, "#define FORW "
"if(e) return e; "
"if(e) goto fail; "
"p += l; "
"len -= l; "
"ret += l\n\n");
@@ -308,13 +308,19 @@ generate_type_decode (const Symbol *s)
"size_t ret = 0, reallen;\n"
"size_t l;\n"
"int i, e;\n\n");
fprintf(codefile, "i = 0;\n"); /* hack to avoid `unused variable' */
fprintf(codefile, "reallen = 0;\n"); /* hack to avoid `unused variable' */
fprintf (codefile, "memset(data, 0, sizeof(*data));\n");
fprintf (codefile, "i = 0;\n"); /* hack to avoid `unused variable' */
fprintf (codefile, "reallen = 0;\n"); /* hack to avoid `unused variable' */
decode_type ("data", s->type);
fprintf (codefile,
"if(size) *size = ret;\n"
"return 0;\n");
fprintf (codefile,
"fail:\n"
"free_%s(data);\n"
"return e;\n",
s->gen_name);
break;
default:
abort ();