Merge pull request #110 from Arkshine/replace-more-snprintf
Replace more snprintf by UTIL_Format.
This commit is contained in:
@ -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__
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user