Merge pull request #110 from Arkshine/replace-more-snprintf
Replace more snprintf by UTIL_Format.
This commit is contained in:
@ -11,16 +11,10 @@
|
||||
// MySQL Module
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "amxxmodule.h"
|
||||
#include "MysqlDriver.h"
|
||||
#include "MysqlDatabase.h"
|
||||
|
||||
#if defined WIN32
|
||||
#define snprintf _snprintf
|
||||
#define strncasecmp strnicmp
|
||||
#endif
|
||||
|
||||
using namespace SourceMod;
|
||||
|
||||
bool MysqlDriver::IsCompatDriver(const char *namestring)
|
||||
@ -53,7 +47,7 @@ IDatabase *MysqlDriver::_Connect(DatabaseInfo *info, int *errcode, char *error,
|
||||
*errcode = -1;
|
||||
if (error && maxlength)
|
||||
{
|
||||
snprintf(error, maxlength, "Initialization failed");
|
||||
UTIL_Format(error, maxlength, "Initialization failed");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -78,7 +72,7 @@ IDatabase *MysqlDriver::_Connect(DatabaseInfo *info, int *errcode, char *error,
|
||||
}
|
||||
if (error && maxlength)
|
||||
{
|
||||
snprintf(error, maxlength, "%s", mysql_error(mysql));
|
||||
UTIL_Format(error, maxlength, "%s", mysql_error(mysql));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -11,16 +11,11 @@
|
||||
// MySQL Module
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "amxxmodule.h"
|
||||
#include "MysqlQuery.h"
|
||||
#include "MysqlDatabase.h"
|
||||
#include "MysqlResultSet.h"
|
||||
|
||||
#if defined WIN32
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
using namespace SourceMod;
|
||||
|
||||
MysqlQuery::MysqlQuery(const char *querystring, MysqlDatabase *db) :
|
||||
@ -95,7 +90,7 @@ bool MysqlQuery::ExecuteR(QueryInfo *info, char *error, size_t maxlength)
|
||||
info->rs = NULL;
|
||||
if (error && maxlength)
|
||||
{
|
||||
snprintf(error, maxlength, "%s", mysql_error(m_pDatabase->m_pMysql));
|
||||
UTIL_Format(error, maxlength, "%s", mysql_error(m_pDatabase->m_pMysql));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -3124,3 +3124,21 @@ unsigned short FixedUnsigned16( float value, float scale )
|
||||
return (unsigned short)output;
|
||||
}
|
||||
#endif // USE_METAMOD
|
||||
|
||||
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
size_t len = vsnprintf(buffer, maxlength, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (len >= maxlength)
|
||||
{
|
||||
buffer[maxlength - 1] = '\0';
|
||||
return (maxlength - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
@ -2495,4 +2495,6 @@ void Mem_Deallocator(const char *sourceFile, const unsigned int sourceLine, cons
|
||||
|
||||
#endif //MEMORY_TEST
|
||||
|
||||
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
|
||||
|
||||
#endif // #ifndef __AMXXMODULE_H__
|
||||
|
Reference in New Issue
Block a user