mirror of
https://github.com/AppleWin/AppleWin.git
synced 2026-04-20 15:17:50 +00:00
More cleanup (PR #1357)
SoundBuffer: move Windows only flags to DXSoundBuffer. Remove out of date _MSC_VER checks (pre-VS2019).
This commit is contained in:
+1
-24
@@ -17,29 +17,7 @@ std::string StrFormatV(const char* format, va_list va)
|
||||
{
|
||||
size_t const bufsz_base = 2048; // Big enough for most cases.
|
||||
char buf[bufsz_base];
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4996) // warning _vsnprintf() is unsafe.
|
||||
// VS2013 or before, _vsnprintf() cannot return required buffer size in case of overflow.
|
||||
// MSVC seems fine not needing va_copy(), otherwise va_copy() may need to be called twice
|
||||
// to be accurate. Not calling va_copy() here to keep things simpler.
|
||||
int len = _vsnprintf(buf, sizeof(buf), format, va);
|
||||
if (len >= 0 && size_t(len) <= sizeof(buf))
|
||||
{
|
||||
// _vsnprintf() can fill up the full buffer without nul termination.
|
||||
return std::string(buf, size_t(len)); // No overflow.
|
||||
}
|
||||
else
|
||||
{
|
||||
// Overflow, need bigger buffer.
|
||||
len = _vsnprintf(NULL, 0, format, va); // Get required buffer size.
|
||||
std::string s(size_t(len), '\0');
|
||||
len = _vsnprintf(&(*s.begin()), s.length() + 1, format, va);
|
||||
assert(size_t(len) == s.length());
|
||||
return s;
|
||||
}
|
||||
#pragma warning(pop)
|
||||
#else
|
||||
|
||||
// Need to call va_copy() so va can be used potentially for a second time.
|
||||
// glibc on Linux *certainly* needs this while MSVC is fine without it though.
|
||||
va_list va_copied;
|
||||
@@ -63,5 +41,4 @@ std::string StrFormatV(const char* format, va_list va)
|
||||
assert(size_t(len) == s.length());
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user