It's generally not a good idea to preallocate buffers for use with sprintf; it's much better to use xasprintf. I've changed your patch accordingly

BTW, sprintf should never be used, at the very least, use snprintf