Type safety and variable initialization in ASN.1 generated code

This commit is contained in:
Asanka Herath
2010-06-02 21:08:33 -04:00
parent e9160dbcfa
commit d25d9476b7
2 changed files with 6 additions and 6 deletions

View File

@@ -288,8 +288,8 @@ encode_type (const char *name, const Type *t, const char *tmpstr)
fprintf(codefile,
"{\n"
"struct heim_octet_string *val;\n"
"size_t elen, totallen = 0;\n"
"int eret;\n");
"size_t elen = 0, totallen = 0;\n"
"int eret = 0;\n");
fprintf(codefile,
"if ((%s)->len > UINT_MAX/sizeof(val[0]))\n"
@@ -535,8 +535,8 @@ generate_type_encode (const Symbol *s)
case TChoice:
fprintf (codefile,
"size_t ret = 0;\n"
"size_t l;\n"
"int i, e;\n\n");
"size_t l, i;\n"
"int e;\n\n");
fprintf(codefile, "i = 0;\n"); /* hack to avoid `unused variable' */
encode_type("data", s->type, "Top");

View File

@@ -187,13 +187,13 @@ length_type (const char *name, const Type *t,
fprintf (codefile,
"{\n"
"int %s_oldret = %s;\n"
"size_t %s_oldret = %s;\n"
"int i;\n"
"%s = 0;\n",
tmpstr, variable, variable);
fprintf (codefile, "for(i = (%s)->len - 1; i >= 0; --i){\n", name);
fprintf (codefile, "int %s_for_oldret = %s;\n"
fprintf (codefile, "size_t %s_for_oldret = %s;\n"
"%s = 0;\n", tmpstr, variable, variable);
if (asprintf (&n, "&(%s)->val[i]", name) < 0 || n == NULL)
errx(1, "malloc");