Switch from malloc to calloc in addFlags

This commit is contained in:
Tobias Bergkvist 2021-12-01 23:07:30 +01:00
parent 97d62a90f5
commit 3997e9de67
3 changed files with 3 additions and 3 deletions

View File

@ -155,7 +155,7 @@ addFlags() {
flag=$(escapeStringLiteral "${flags[$n]}")
result="$result ${var}[$((n+1))] = \"$flag\";"$'\n'
done
printf ' %s\n' "char **$var = malloc(sizeof(*$var) * ($((n+1)) + argc));"
printf ' %s\n' "char **$var = calloc($((n+1)) + argc, sizeof(*$var));"
printf ' %s\n' "assert($var != NULL);"
printf ' %s\n' "${var}[0] = argv[0];"
printf '%s' "$result"

View File

@ -7,7 +7,7 @@
#include <assert.h>
int main(int argc, char **argv) {
char **argv_tmp = malloc(sizeof(*argv_tmp) * (5 + argc));
char **argv_tmp = calloc(5 + argc, sizeof(*argv_tmp));
assert(argv_tmp != NULL);
argv_tmp[0] = argv[0];
argv_tmp[1] = "-x";

View File

@ -47,7 +47,7 @@ int main(int argc, char **argv) {
set_env_suffix("PATH", ":", "/usr/local/bin/");
putenv("MESSAGE2=WORLD");
char **argv_tmp = malloc(sizeof(*argv_tmp) * (4 + argc));
char **argv_tmp = calloc(4 + argc, sizeof(*argv_tmp));
assert(argv_tmp != NULL);
argv_tmp[0] = argv[0];
argv_tmp[1] = "-x";