Replace more snprintf by UTIL_Format.

This commit is contained in:
Arkshine
2014-08-08 12:44:37 +02:00
parent c22bb12c1e
commit b47aa6871d
61 changed files with 417 additions and 72 deletions

View File

@@ -3123,3 +3123,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;
}
}

View File

@@ -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__

View File

@@ -11,15 +11,12 @@
// SQLite Module
//
#include <string.h>
#include <stdio.h>
#include "amxxmodule.h"
#include "SqliteHeaders.h"
#include "SqliteDriver.h"
#include "SqliteDatabase.h"
#if defined WIN32
#define snprintf _snprintf
#define strncasecmp strnicmp
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#else
@@ -65,7 +62,7 @@ IDatabase *SqliteDriver::Connect(DatabaseInfo *info, int *errcode, char *error,
}
if (error)
{
snprintf(error, maxlength, "%s", sqlite3_errmsg(pSql));
UTIL_Format(error, maxlength, "%s", sqlite3_errmsg(pSql));
}
sqlite3_close(pSql);
return NULL;

View File

@@ -11,16 +11,11 @@
// SQLite Module
//
#include <stdio.h>
#include <string.h>
#include "amxxmodule.h"
#include "SqliteQuery.h"
#include "SqliteDatabase.h"
#include "SqliteResultSet.h"
#if defined WIN32
#define snprintf _snprintf
#endif
using namespace SourceMod;
SqliteQuery::SqliteQuery(SqliteDatabase *db, const char *query) :
@@ -97,7 +92,7 @@ bool SqliteQuery::ExecuteR(QueryInfo *info, char *error, size_t maxlength)
{
if (error && maxlength && errmsg)
{
snprintf(error, maxlength, "%s", errmsg);
UTIL_Format(error, maxlength, "%s", errmsg);
}
info->affected_rows = 0;
info->errorcode = err;