I got this code (below) thats basically an snprintf function but a bit slower, meaning it also handles buffer size with malloc/realloc.

The code works how it should up to the point where the realloc changes the address (when the string gets larger and larger over time)... If that happens, the output is completely wrong.

```
bool write_str(char **str, const char *format, ...)
{
    // va arg stuff
    va_list argp;
    va_start(argp, format);
    // remember to have a separate va_list for each v*print function, because v*print consumes the function
    // but in this case it actually doesn't need it
    size_t len = vsnprintf(0, 0, format, argp);
    if(*str)
    {
        *str = realloc(*str, len + 1);
    }
    else
    {
        *str = malloc(len + 1);
        **str = 0;
    }
    if(!*str)
    {
        return false;
    }
    vsnprintf(*str, len, format, argp);
    va_end(argp);
    (*str)[len] = 0;
    return true;
}

```

And that's how you would use the function.

```
char *str = 0;
write_str(&str, "That is how %d use it\n", 2);

```

edit: Comments come from here [Length of each string argument](https://stackoverflow.com/q/61011481/11223349)