From 7ecd1102d02e3144326714738f57f8e7930e7e29 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 17 Aug 2014 12:04:10 +0000 Subject: [PATCH] b58enc: Allocate buf on the stack rather than heap --- base58.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/base58.c b/base58.c index 8828dbe..7e78e11 100644 --- a/base58.c +++ b/base58.c @@ -14,7 +14,6 @@ #include #include #include -#include #include bool (*b58_sha256_impl)(void *, const void *, size_t) = NULL; @@ -124,15 +123,12 @@ bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz) const uint8_t *bin = data; int i, j, carry, high, zcount = 0; size_t size; - uint8_t *buf; while (zcount < binsz && !bin[zcount]) ++zcount; size = (binsz - zcount) * 138 / 100 + 1; - buf = malloc(size); - if (!buf) - return false; + uint8_t buf[size]; memset(buf, 0, size); for (i = zcount, high = size - 1; i < binsz; ++i, high = j) @@ -149,7 +145,6 @@ bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz) if (*b58sz <= zcount + size - j) { - free(buf); *b58sz = zcount + size - j + 1; return false; } @@ -161,6 +156,5 @@ bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz) b58[i] = '\0'; *b58sz = i + 1; - free(buf); return true; }