From 7d3e2eebb2f560424f7cae5ab84d8cdd5e12f245 Mon Sep 17 00:00:00 2001 From: Tim Ruehsen Date: Mon, 12 May 2014 12:27:32 +0200 Subject: [PATCH] use alloca instead of malloc for command buffer allocation --- src/psl2c.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/psl2c.c b/src/psl2c.c index 48643bc..c3364fa 100644 --- a/src/psl2c.c +++ b/src/psl2c.c @@ -365,7 +365,8 @@ int main(int argc, const char **argv) if ((fpout = fopen(argv[2], "w"))) { FILE *pp; struct stat st; - char *cmd, checksum[64] = ""; + size_t cmdsize = 16 + strlen(argv[1]); + char *cmd = alloca(cmdsize), checksum[64] = ""; _add_punycode_if_needed(psl->suffixes); _add_punycode_if_needed(psl->suffix_exceptions); @@ -373,14 +374,11 @@ int main(int argc, const char **argv) _print_psl_entries(fpout, psl->suffixes, "suffixes"); _print_psl_entries(fpout, psl->suffix_exceptions, "suffix_exceptions"); - if ((cmd = malloc(16 + strlen(argv[1])))) { - snprintf(cmd, 16 + strlen(argv[1]), "sha1sum %s", argv[1]); - if ((pp = popen(cmd, "r"))) { - if (fscanf(pp, "%63[0-9a-zA-Z]", checksum) < 1) - *checksum = 0; - pclose(pp); - } - free(cmd); + snprintf(cmd, cmdsize, "sha1sum %s", argv[1]); + if ((pp = popen(cmd, "r"))) { + if (fscanf(pp, "%63[0-9a-zA-Z]", checksum) < 1) + *checksum = 0; + pclose(pp); } if (stat(argv[1], &st) != 0)