Skip to content

Commit 1680b92

Browse files
committed
Make stringWithFormat not invoke undefined behaviour with Visual Studio 2017
warning C4840: non-portable use of class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' as an argument to a variadic function
1 parent 31e33ef commit 1680b92

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/IDE/TypeReconstruction.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ using namespace swift;
2929
// FIXME: replace with std::string and StringRef as appropriate to each case.
3030
typedef const std::string ConstString;
3131

32-
static std::string stringWithFormat(const std::string fmt_str, ...) {
33-
int final_n, n = ((int)fmt_str.size()) * 2;
32+
static std::string stringWithFormat(const char *fmt_str, ...) {
33+
int final_n, n = ((int)strlen(fmt_str)) * 2;
3434
std::string str;
3535
std::unique_ptr<char[]> formatted;
3636
va_list ap;
3737
while (1) {
3838
formatted.reset(new char[n]);
39-
strcpy(&formatted[0], fmt_str.c_str());
39+
strcpy(&formatted[0], fmt_str);
4040
va_start(ap, fmt_str);
41-
final_n = vsnprintf(&formatted[0], n, fmt_str.c_str(), ap);
41+
final_n = vsnprintf(&formatted[0], n, fmt_str, ap);
4242
va_end(ap);
4343
if (final_n < 0 || final_n >= n)
4444
n += abs(final_n - n + 1);

0 commit comments

Comments
 (0)