[MD] Replace the unsafe func 'snprintf' with a safe one 'snprintf_s' in soft_dp_log.h

This commit is contained in:
mayang 2020-09-10 20:14:21 +08:00
parent 9223915fb2
commit 56acc65619
1 changed files with 6 additions and 7 deletions

View File

@ -65,19 +65,18 @@
#elif defined(USE_GLOG)
#include <securec.h>
#include <cstdio>
#include "glog/logging.h"
template <typename... Args>
inline std::string GetFormatString(const char *format, Args... args) {
char buf[BUFSIZ];
int new_len = snprintf(&buf[0], BUFSIZ, format, args...);
new_len++;
if (new_len > BUFSIZ) {
std::vector<char> buf2(new_len);
snprintf(buf2.data(), new_len, format, args...);
return std::string(buf2.data());
}
#ifdef _WIN32
_snprintf_s(&buf[0], BUFSIZ, BUFSIZ - 1, format, args...);
#else
snprintf_s(&buf[0], BUFSIZ, BUFSIZ - 1, format, args...);
#endif
return buf;
}