Merge pull request #110 from Arkshine/replace-more-snprintf

Replace more snprintf by UTIL_Format.
This commit is contained in:
Vincent Herbet 2014-08-08 20:38:38 +02:00
commit 570c9cfc6b
63 changed files with 438 additions and 79 deletions

View File

@ -12,10 +12,6 @@
#include "CLang.h"
#include "format.h"
#if defined(__linux__) || defined(__APPLE__)
#define _snprintf snprintf
#endif
#define LITIDX_NONE 0
#define LITIDX_BRACKET 1
#define LITIDX_DEFINITION 2

View File

@ -4092,10 +4092,6 @@ int AMXAPI amx_GetLibraries(AMX *amx)
return numLibraries;
}
#if defined(__linux__) || defined(__APPLE__)
#define _snprintf snprintf
#endif
const char *AMXAPI amx_GetLibrary(AMX *amx, int index, char *buffer, int len)
{
AMX_HEADER *hdr = (AMX_HEADER *)amx->base;

View File

@ -97,7 +97,7 @@ size_t AddLibrariesFromString(const char *name, LibType type, LibSource src, voi
char *ptr, *p, s;
size_t count = 0;
snprintf(buffer, sizeof(buffer)-1, "%s", name);
UTIL_Format(buffer, sizeof(buffer)-1, "%s", name);
ptr = buffer;
p = buffer;

View File

@ -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;
}
}

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

@ -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;
}
}

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

@ -12,6 +12,24 @@
#include <stdio.h>
#include "commctrl.h"
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;
}
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
@ -178,7 +196,7 @@ void UpdateListBox(HWND hDlg) {
//if ((*b).getPosition() < 1) // umm... naaah!
//continue;
_snprintf(tempbuffer, 1023, "%s", (*b).getName());
UTIL_Format(tempbuffer, sizeof(tempbuffer)-1, "%s", (*b).getName());
SendMessage( // returns LRESULT in lResult
listbox, // handle to destination control
@ -325,7 +343,7 @@ void SaveChanges(HWND hDlg) {
UpdateListBox(hDlg);
char buffer[256];
_snprintf(buffer, 255, "New rank of %s: %d", name, newPosition);
UTIL_Format(buffer, sizeof(buffer)-1, "New rank of %s: %d", name, newPosition);
MessageBox(hDlg, buffer, "Update succeeded", MB_OK);
// In the listbox, we need to reselect the item we just updated. Use the new name.

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

@ -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;
}
}

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

@ -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;
}
}

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

@ -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;
}
}

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

@ -21,8 +21,7 @@ int g_CameraCount;
TraceResult g_tr;
#define BUFFERSIZE 1023
char g_buffer[BUFFERSIZE + 1];
char g_buffer[1024];
void UTIL_SetSize(edict_t *pev, const Vector &vecMin, const Vector &vecMax)
{
@ -870,7 +869,7 @@ static cell AMX_NATIVE_CALL traceresult(AMX *amx, cell *params)
// (jghg)
static cell AMX_NATIVE_CALL get_string(AMX *amx, cell *params) // (string, returnstring[], length)
{
snprintf(g_buffer, BUFFERSIZE, "%s", STRING(params[1]));
UTIL_Format(g_buffer, sizeof(g_buffer)-1, "%s", STRING(params[1]));
return MF_SetAmxString(amx, params[2], g_buffer, params[3]);
}

View File

@ -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;
}
}

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

@ -299,23 +299,23 @@ static cell AMX_NATIVE_CALL amx_pev(AMX *amx,cell *params)
return num;
} else if (ValType & Ret_Int) {
char temp[32];
snprintf(temp, 31, "%d", rets.i);
UTIL_Format(temp, sizeof(temp)-1, "%d", rets.i);
return MF_SetAmxString(amx, params[3], temp, size);
} else if (ValType == Ret_Float) {
char temp[32];
snprintf(temp, 31, "%f", rets.f);
UTIL_Format(temp, sizeof(temp)-1, "%f", rets.f);
return MF_SetAmxString(amx, params[3], temp, size);
} else if (ValType == Ret_Vec) {
char temp[32];
snprintf(temp, 31, "%f %f %f", vr.x, vr.y, vr.z);
UTIL_Format(temp, sizeof(temp)-1, "%f %f %f", vr.x, vr.y, vr.z);
return MF_SetAmxString(amx, params[3], temp, size);
} else if (ValType == Ret_Bytes2) {
char temp[32];
snprintf(temp, 31, "%d %d", rets.ba[0], rets.ba[1]);
UTIL_Format(temp, sizeof(temp)-1, "%d %d", rets.ba[0], rets.ba[1]);
return MF_SetAmxString(amx, params[3], temp, size);
} else if (ValType == Ret_Bytes4) {
char temp[32];
snprintf(temp, 31, "%d %d %d %d", rets.ba[0], rets.ba[1], rets.ba[2], rets.ba[3]);
UTIL_Format(temp, sizeof(temp)-1, "%d %d %d %d", rets.ba[0], rets.ba[1], rets.ba[2], rets.ba[3]);
return MF_SetAmxString(amx, params[3], temp, size);
}

View File

@ -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;
}
}

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

@ -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;
}
}

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

@ -17,10 +17,6 @@
#include "GeoIP2/maxminddb.h"
#include "amxxmodule.h"
#if defined(WIN32)
#define snprintf _snprintf
#endif
extern AMX_NATIVE_INFO geoip_natives[];
#endif //_INCLUDE_GEOIPAMXX_H

View File

@ -192,7 +192,7 @@ bool loadDatabase()
// MF_BuildPathname not used because backslash
// makes CreateFileMapping failing under windows.
snprintf(file, sizeof(file)-1, "%s/%s/GeoLite2-%s.mmdb", modName, dataDir, databases[i]);
UTIL_Format(file, sizeof(file)-1, "%s/%s/GeoLite2-%s.mmdb", modName, dataDir, databases[i]);
status = MMDB_open(file, MMDB_MODE_MMAP, &HandleDB);

View File

@ -144,7 +144,7 @@ static cell AMX_NATIVE_CALL amx_geoip_region_code(AMX *amx, cell *params)
if (countryCode)
{
finalLength = length + 1; // + 1 for dash.
snprintf(code, finalLength + 1, "%s-", countryCode); // + EOS.
UTIL_Format(code, finalLength + 1, "%s-", countryCode); // + EOS.
const char *pathRegion[] = { "subdivisions", "0", "iso_code", NULL }; // First result.
const char *regionCode = lookupString(ip, pathRegion, &length);

View File

@ -16,10 +16,6 @@
#include "geoip_main.h"
#if defined(WIN32)
#define snprintf _snprintf
#endif
char *stripPort(char *ip);
bool lookupByIp(const char *ip, const char **path, MMDB_entry_data_s *result);

View File

@ -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;
}
}

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

@ -108,7 +108,7 @@ static void read_mirror(char *input)
*data='\0';
// mark down the source
snprintf(source, sizeof(source)-1, "%s", input);
UTIL_Format(source, sizeof(source)-1, "%s", input);
*data=old;
@ -128,13 +128,13 @@ static void read_mirror(char *input)
old=*data;
*data='\0';
snprintf(dest, sizeof(dest)-1, "%s", data2);
UTIL_Format(dest, sizeof(dest)-1, "%s", data2);
*data=old;
if (strcmp(dest, CurrentModName)==0)
{
snprintf(CurrentModName, sizeof(CurrentModName)-1, "%s", source);
UTIL_Format(CurrentModName, sizeof(CurrentModName)-1, "%s", source);
}
}
@ -313,7 +313,7 @@ int ReadConfig(void)
FILE *fp=fopen(FileName,"r");
snprintf(CurrentModName, sizeof(CurrentModName)-1, "%s", MF_GetModname());
UTIL_Format(CurrentModName, sizeof(CurrentModName)-1, "%s", MF_GetModname());
if (!fp)
{

View File

@ -21,12 +21,12 @@
#define CHECK_FUNCTION(x) \
if (x < 0 || x >= HAM_LAST_ENTRY_DONT_USE_ME_LOL) { \
char msg[1024]; \
snprintf(msg, sizeof(msg)-1, "Function out of bounds. Got: %d Max: %d",x, HAM_LAST_ENTRY_DONT_USE_ME_LOL - 1); \
UTIL_Format(msg, sizeof(msg)-1, "Function out of bounds. Got: %d Max: %d", x, HAM_LAST_ENTRY_DONT_USE_ME_LOL - 1); \
FailPlugin(amx, x, HAM_INVALID_FUNC, msg); \
return 0; \
} else if (hooklist[x].isset == 0) { \
char msg[1024]; \
snprintf(msg, sizeof(msg)-1, "Function %s is not configured in hamdata.ini.",hooklist[x].name); \
UTIL_Format(msg, sizeof(msg)-1, "Function %s is not configured in hamdata.ini.", hooklist[x].name); \
FailPlugin(amx, x, HAM_FUNC_NOT_CONFIGURED, msg); \
return 0; \
}

View File

@ -61,7 +61,7 @@ public:
size_t len=strlen(name);
ent=new char[len+1];
snprintf(ent,len+1,"%s",name);
UTIL_Format(ent, len + 1, "%s", name);
};
~Hook()

View File

@ -712,7 +712,7 @@ static cell AMX_NATIVE_CALL RegisterHamFromEntity(AMX *amx, cell *params)
// It may very well be wrong (such as lots of TS weapons have the same classname)
// but it's the best we can do, and better than nothing.
// (only used for display)
snprintf(classname, sizeof(classname) - 1, "%s", STRING(Entity->v.classname));
UTIL_Format(classname, sizeof(classname) - 1, "%s", STRING(Entity->v.classname));
// If we got here, the function is not hooked
Hook *hook = new Hook(vtable, hooklist[func].vtid, hooklist[func].targetfunc, hooklist[func].isvoid, hooklist[func].needsretbuf, hooklist[func].paramcount, classname);

View File

@ -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;
}
}

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,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;
}

View File

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

View File

@ -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;
}
}

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

@ -31,7 +31,7 @@ void ParticleManager::ReadFile(void)
char FileName[256];
snprintf(FileName,sizeof(FileName)-1,"%s/ns.ps",MF_GetModname());
UTIL_Format(FileName, sizeof(FileName)-1, "%s/ns.ps", MF_GetModname());
FILE *fp=fopen(FileName,"r");
if (!fp)

View File

@ -28,7 +28,7 @@ void TitleManager::LoadTitles(void)
char FileName[128];
snprintf(FileName,127,"%s/titles.txt",MF_GetModname());
UTIL_Format(FileName, sizeof(FileName)-1, "%s/titles.txt", MF_GetModname());
FILE *fp=fopen(FileName,"r");

View File

@ -86,9 +86,9 @@ void MFuncs_Initialize(void)
char FileName[256];
DLHANDLE DLLBase;
#ifdef __linux__
snprintf(FileName,sizeof(FileName)-1,"%s/dlls/ns_i386.so",MF_GetModname());
UTIL_Format(FileName,sizeof(FileName)-1,"%s/dlls/ns_i386.so",MF_GetModname());
#else
snprintf(FileName,sizeof(FileName)-1,"%s\\dlls\\ns.dll",MF_GetModname());
UTIL_Format(FileName, sizeof(FileName)-1, "%s\\dlls\\ns.dll", MF_GetModname());
#endif
DLLBase=DLOPEN(FileName);

View File

@ -49,7 +49,7 @@ cell PSKeyValueI(const char *name, AMX *amx, cell *params)
char StrData[1024];
snprintf(StrData,sizeof(StrData)-1,"%d",params[2]);
UTIL_Format(StrData, sizeof(StrData)-1, "%d", params[2]);
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
kvd.szKeyName=name;
@ -72,7 +72,7 @@ cell PSKeyValueF(const char *name, AMX *amx, cell *params)
char StrData[1024];
snprintf(StrData,sizeof(StrData)-1,"%f",amx_ctof2(params[2]));
UTIL_Format(StrData, sizeof(StrData)-1, "%f", amx_ctof2(params[2]));
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
kvd.szKeyName=name;

View File

@ -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;
}
}

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

@ -17,10 +17,6 @@
#include "Binary.h"
#include "CString.h"
#if defined(__linux__) || defined(__APPLE__)
#define _snprintf snprintf
#endif
/**
* :TODO: This beast calls strcpy()/new() way too much by creating new strings on the stack.
* That's easily remedied and it should be fixed?
@ -366,7 +362,7 @@ bool NVault::GetValue(const char *key, time_t &stamp, char buffer[], size_t len)
sVal = m_Hash.Retrieve(sKey, st);
stamp = st;
_snprintf(buffer, len, "%s", sVal.c_str());
UTIL_Format(buffer, len, "%s", sVal.c_str());
return true;
}

View File

@ -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;
}
}

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

@ -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;
}
}

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

@ -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;
}
}

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

@ -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;
}
}

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;

View File

@ -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;
}
}

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

@ -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;
}
}

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

@ -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;
}
}

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

@ -28,8 +28,7 @@
*/
#include "MemoryUtils.h"
#include <string.h>
#include <stdio.h>
#include "amxxmodule.h"
#if defined(__linux__)
#include <fcntl.h>
@ -638,7 +637,7 @@ bool MemoryUtils::GetLibraryOfAddress(const void *libPtr, char *buffer, size_t m
return false;
}
const char *dllpath = info.dli_fname;
snprintf(buffer, maxlength, "%s", dllpath);
UTIL_Format(buffer, maxlength, "%s", dllpath);
if (base)
{
*base = (uintptr_t)info.dli_fbase;