How do you know if it is large enough? Well, your current method is almost right. It just needs tweaking. And remember to allow for the minus sign (if required).
It might be simpler to just use a fixed size, say 80 bytes, that should be adequate.
Look at the context. The value input by the user may be negative or positive.
But at line 57 we have while (n>0)
If n is negative, the loop will never execute as it will fail this comparison. So I used that as a somewhat crude way of handling the situation. This isn't necessarily the best approach, as it doesn't mirror exactly the code inside the function good_itoa()
I look at it this way, right now we are interested in the internal workings of this function. But if you think of it as being like the library function (which exists for some compilers, but is not standardised), the user of such a function will treat it as a 'black box' which does something. In practice we would just pass a generously large buffer to the function, without going to the trouble of trying to pre-calculate the exact size.
My preferred approach would be to use a C++ std::string and let the function allocate this for itself, without the user having to be concerned with the size. Though the current code doesn't use any C++ features.