Merge pull request #321 from ennorehling/feature/fixme-base36-static

eliminate static variable leak and allocation from base36
This commit is contained in:
Enno Rehling 2015-10-27 13:30:12 +01:00
commit 185a2ee29c
1 changed files with 3 additions and 11 deletions

View File

@ -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) {