[Bug 22536] New: SetErrorStringWithVarArg needs to use vscprintf on Windows

Bug ID 22536
Summary SetErrorStringWithVarArg needs to use vscprintf on Windows
Product lldb
Version unspecified
Hardware PC
OS Windows NT
Status NEW
Severity normal
Priority P
Component All Bugs
Assignee amccarth@google.com
Reporter zturner@google.com
CC lldb-dev@cs.uiuc.edu
Classification Unclassified

In Error::SetErrorStringWithVarArg(), lldb calls vsnprintf.  To be standards
conformant, the function must return "The number of characters that would have
been written if n had been sufficiently large, not counting the terminating
null character."  ([http://www.cplusplus.com/reference/cstdio/vsnprintf/](http://www.cplusplus.com/reference/cstdio/vsnprintf/)).  On
Windows, apparently, "if the number of characters to write is greater than
count, these functions return -1 indicating that output has been truncated."

This sometimes triggers a segfault in this function  (Thanks to ki9a for
finding this).

It seems that on Windows we need to call _vscprintf
([https://msdn.microsoft.com/en-us/library/w05tbk72.aspx](https://msdn.microsoft.com/en-us/library/w05tbk72.aspx)) in order to determine
the correct buffer size before calling vsnprintf.

Not sure how to reproduce this in live code, but a test that calls
SBError::SetExpressionErrorWithFormat() should be able to for this code path,
and would also be a good test to have anyway.