Browse Source

core: do not use va_copy since Visual Studio doesn’t know about it.

legacy
Sam Hocevar sam 12 years ago
parent
commit
dff7a5b72c
2 changed files with 13 additions and 7 deletions
  1. +8
    -7
      src/core/string.cpp
  2. +5
    -0
      test/unit/string.cpp

+ 8
- 7
src/core/string.cpp View File

@@ -29,19 +29,20 @@ namespace lol
String String::Printf(char const *format, ...)
{
String ret;

va_list ap, aq;
va_start(ap, format);
va_copy(aq, ap);
va_list ap;

/* vsnprintf() tells us how many character we need, and we need to
* add one for the terminating null byte. */
size_t needed = vsnprintf(NULL, 0, format, aq) + 1;
va_start(ap, format);
size_t needed = vsnprintf(NULL, 0, format, ap) + 1;
va_end(ap);

((Super &)ret).Reserve(needed);
ret.m_count = needed;
vsnprintf(&ret[0], needed, format, ap);

va_end(aq);
/* We don’t use va_copy because Visual Studio 2010 does not support it. */
va_start(ap, format);
std::vsnprintf(&ret[0], needed, format, ap);
va_end(ap);

return ret;


+ 5
- 0
test/unit/string.cpp View File

@@ -127,6 +127,11 @@ LOLUNIT_FIXTURE(StringTest)
String s2 = String::Printf("%d%x", 3, 10);

LOLUNIT_ASSERT(s1 == s2);

String s3 = "abc 3";
String s4 = String::Printf("abc %d", 3);

LOLUNIT_ASSERT(s3 == s4);
}
};



Loading…
Cancel
Save