forked from github/server
Merge pull request #321 from ennorehling/feature/fixme-base36-static
eliminate static variable leak and allocation from base36
This commit is contained in:
commit
185a2ee29c
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue