From f80f37def3ad0a527261d2459de50898608a8ec2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 27 Oct 2015 12:48:34 +0100 Subject: [PATCH] eliminate static variable leak and allocation from base36 --- src/util/base36.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/util/base36.c b/src/util/base36.c index 65c9db812..7edb46027 100644 --- a/src/util/base36.c +++ b/src/util/base36.c @@ -54,22 +54,14 @@ int atoi36(const char *str) const char *itoab(int i, int base) { - const int maxlen = 20; - static char **as = NULL; // FIXME: static return value + static char sstr[80]; char *s, *dst; static int index = 0; /* STATIC_XCALL: used across calls */ int neg = 0; - if (!as) { - int j; - char *x = (char *)calloc(sizeof(char), maxlen * 4); /* STATIC_LEAK: malloc in static variable */ - as = (char **)calloc(sizeof(char *), 4); - for (j = 0; j != 4; ++j) - as[j] = x + j * maxlen; - } - s = as[index]; + s = sstr + (index * 20); index = (index + 1) & 3; /* quick for % 4 */ - dst = s + maxlen - 1; + dst = s + 19; (*dst--) = 0; if (i != 0) { if (i < 0) {