From b55ffeceaeea973e457ac1e3bdf44acb20417096 Mon Sep 17 00:00:00 2001 From: Enno Boland Date: Thu, 16 Jun 2016 06:50:14 +0200 Subject: [PATCH] lib/util_hash.c: write directly to malloced string instead if coping it over --- lib/util_hash.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/util_hash.c b/lib/util_hash.c index b170b432..f13f1b0e 100644 --- a/lib/util_hash.c +++ b/lib/util_hash.c @@ -132,17 +132,18 @@ xbps_file_hash_raw(const char *file) char * xbps_file_hash(const char *file) { - char *res, hash[SHA256_DIGEST_LENGTH * 2 + 1]; + char *hash; unsigned char *digest; if (!(digest = xbps_file_hash_raw(file))) return NULL; + hash = malloc(SHA256_DIGEST_LENGTH * 2 + 1); + assert(hash); digest2string(digest, hash, SHA256_DIGEST_LENGTH); - res = strdup(hash); free(digest); - return res; + return hash; } int