I'm looking for a way to use some variant of vsnprintf()
with a buffer that can possibly be longer than the input buffer without triggering an error to the user.
So far I've found that vsnprintf()
and its variants silently truncate the string when the buffer is too small but they don't return the actual length of the string so I can't try it again with a longer buffer. They return -1.
On the other hand, the vsnprintf_s()
variants, when faced with this error, call
_VALIDATE_RETURN(("Buffer too small", 0), ERANGE, -1);
Which in turn eventually calls _CrtDbgReportW()
, possibly only in debug.
They do this even before calling the user supplied "invalid parameter handler"
All I want is to be able to recover with no user interaction by getting the actual size I need to allocate and calling the function again. is that possible?