1
0
mirror of synced 2025-04-21 22:25:55 +03:00

Fixed problems with Visual Studio 2013

This commit is contained in:
yhirose 2017-12-07 13:10:20 -05:00
parent 0968d71c96
commit f35f2b23fa

View File

@ -11,12 +11,12 @@
#ifdef _WIN32 #ifdef _WIN32
#ifndef _CRT_SECURE_NO_WARNINGS #ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#endif //_CRT_SECURE_NO_WARNINGS #endif
#ifndef _CRT_NONSTDC_NO_DEPRECATE #ifndef _CRT_NONSTDC_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE #define _CRT_NONSTDC_NO_DEPRECATE
#endif //_CRT_NONSTDC_NO_DEPRECATE #endif
#if (_MSC_VER && _MSC_VER < 1900) #if defined(_MSC_VER) && _MSC_VER < 1900
#define snprintf _snprintf_s #define snprintf _snprintf_s
#endif #endif
@ -344,15 +344,21 @@ private:
template <typename ...Args> template <typename ...Args>
inline void socket_printf(Stream& strm, const char* fmt, const Args& ...args) inline void socket_printf(Stream& strm, const char* fmt, const Args& ...args)
{ {
char buf[BUFSIZ]; const auto bufsiz = 2048;
auto n = snprintf(buf, BUFSIZ, fmt, args...); char buf[bufsiz];
if (n > 0) {
if (n >= BUFSIZ) {
std::vector<char> glowable_buf(BUFSIZ);
while (n >= static_cast<int>(glowable_buf.size())) { auto n = snprintf(buf, bufsiz - 1, fmt, args...);
if (n > 0) {
if (n >= bufsiz - 1) {
std::vector<char> glowable_buf(bufsiz);
while (n >= static_cast<int>(glowable_buf.size() - 1)) {
glowable_buf.resize(glowable_buf.size() * 2); glowable_buf.resize(glowable_buf.size() * 2);
n = snprintf(&glowable_buf[0], glowable_buf.size(), fmt, args...); #if defined(_MSC_VER) && _MSC_VER < 1900
n = _snprintf_s(&glowable_buf[0], glowable_buf.size(), glowable_buf.size() - 1, fmt, args...);
#else
n = snprintf(&glowable_buf[0], glowable_buf.size() - 1, fmt, args...);
#endif
} }
strm.write(&glowable_buf[0], n); strm.write(&glowable_buf[0], n);
} else { } else {
@ -763,7 +769,7 @@ inline std::string encode_url(const std::string& s)
if (s[i] < 0) { if (s[i] < 0) {
result += '%'; result += '%';
char hex[4]; char hex[4];
size_t len = snprintf(hex, sizeof(hex), "%02X", (unsigned char)s[i]); size_t len = snprintf(hex, sizeof(hex) - 1, "%02X", (unsigned char)s[i]);
assert(len == 2); assert(len == 2);
result.append(hex, len); result.append(hex, len);
} else { } else {