asn1: Use calloc() in generated C code

This commit is contained in:
Nicolas Williams
2022-01-12 17:01:37 -06:00
parent 1fe3d293e1
commit f0c46e7830
3 changed files with 7 additions and 7 deletions

View File

@@ -313,7 +313,7 @@ encode_type (const char *name, const Type *t, const char *tmpstr)
name);
fprintf(codefile,
"val = malloc(sizeof(val[0]) * (%s)->len);\n"
"val = calloc(1, sizeof(val[0]) * (%s)->len);\n"
"if (val == NULL && (%s)->len != 0) return ENOMEM;\n",
name, name);
@@ -465,7 +465,7 @@ encode_type (const char *name, const Type *t, const char *tmpstr)
"size_t l2_%s, lensave_%s = len;\n"
"len = length_%s(%s);\n"
/* Allocate a temp buffer for the encoder */
"if ((p = pfree_%s = malloc(len)) == NULL) return ENOMEM;\n"
"if ((p = pfree_%s = calloc(1, len)) == NULL) return ENOMEM;\n"
/* Make p point to the last byte of the allocated buf */
"p += len - 1;\n",
tmpstr, tmpstr, tmpstr, tmpstr,