Add printf-style warnings to strprintf() and OutputDebugStringF()

This finds about ~150 potential problems with format characters on a 64 bit build.
This commit is contained in:
Wladimir J. van der Laan
2012-09-09 14:43:06 +02:00
parent eabc8f2c81
commit b0a90fbb0c
2 changed files with 42 additions and 9 deletions

View File

@@ -274,7 +274,7 @@ inline int OutputDebugStringF(const char* pszFormat, ...)
return ret;
}
string vstrprintf(const std::string &format, va_list ap)
string vstrprintf(const char *format, va_list ap)
{
char buffer[50000];
char* p = buffer;
@@ -284,7 +284,7 @@ string vstrprintf(const std::string &format, va_list ap)
{
va_list arg_ptr;
va_copy(arg_ptr, ap);
ret = _vsnprintf(p, limit, format.c_str(), arg_ptr);
ret = _vsnprintf(p, limit, format, arg_ptr);
va_end(arg_ptr);
if (ret >= 0 && ret < limit)
break;
@@ -301,7 +301,7 @@ string vstrprintf(const std::string &format, va_list ap)
return str;
}
string real_strprintf(const std::string &format, int dummy, ...)
string real_strprintf(const char *format, int dummy, ...)
{
va_list arg_ptr;
va_start(arg_ptr, dummy);
@@ -310,6 +310,15 @@ string real_strprintf(const std::string &format, int dummy, ...)
return str;
}
string real_strprintf(const std::string &format, int dummy, ...)
{
va_list arg_ptr;
va_start(arg_ptr, dummy);
string str = vstrprintf(format.c_str(), arg_ptr);
va_end(arg_ptr);
return str;
}
bool error(const char *format, ...)
{
va_list arg_ptr;