Can vsnprintf()
return a negative value of magnitude greater than 1? If so, under what circumstances does it do so?
I tried to use %ls
as format specifier for a char array and also tried to copy larger than what array was allocated. In both cases I am getting -1 as return value.
Yes it can, as in "it is allowed to". The circumstances depend on your platform and are not specified or regulated in any way. The only portable thing to do with the return value is to check it for
< 0
to see if there was an error.From the standard (7.21.6.12 (3),
vsnprintf
):Any given platform may of course make additional guarantees about the return value; consult your documentation.