From b47aa6871d44957f31e84c32e2a54e3a02810cc9 Mon Sep 17 00:00:00 2001 From: Arkshine Date: Fri, 8 Aug 2014 12:44:37 +0200 Subject: [PATCH] Replace more snprintf by UTIL_Format. --- amxmodx/CLang.cpp | 4 ---- amxmodx/amx.cpp | 4 ---- amxmodx/libraries.cpp | 2 +- amxmodx/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ amxmodx/sdk/amxxmodule.h | 2 ++ dlls/cstrike/cstrike/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/cstrike/cstrike/sdk/amxxmodule.h | 2 ++ dlls/cstrike/csx/WinCSX/amxxmodule.h | 2 ++ dlls/cstrike/csx/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/cstrike/csx/sdk/amxxmodule.h | 2 ++ dlls/dod/dodfun/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/dod/dodfun/sdk/amxxmodule.h | 2 ++ dlls/dod/dodx/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/dod/dodx/sdk/amxxmodule.h | 2 ++ dlls/engine/engine.cpp | 5 ++--- dlls/engine/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/engine/sdk/amxxmodule.h | 2 ++ dlls/fakemeta/pev.cpp | 10 +++++----- dlls/fakemeta/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/fakemeta/sdk/amxxmodule.h | 2 ++ dlls/fun/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/fun/sdk/amxxmodule.h | 2 ++ dlls/geoip/geoip_main.cpp | 2 +- dlls/geoip/geoip_natives.cpp | 2 +- dlls/geoip/geoip_util.h | 4 ---- dlls/geoip/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/geoip/sdk/amxxmodule.h | 2 ++ dlls/hamsandwich/config_parser.cpp | 8 ++++---- dlls/hamsandwich/ham_utils.h | 4 ++-- dlls/hamsandwich/hook.h | 2 +- dlls/hamsandwich/hook_native.cpp | 2 +- dlls/hamsandwich/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/hamsandwich/sdk/amxxmodule.h | 2 ++ dlls/mysqlx/mysql/MysqlDriver.cpp | 12 +++--------- dlls/mysqlx/mysql/MysqlQuery.cpp | 9 ++------- dlls/mysqlx/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/mysqlx/sdk/amxxmodule.h | 2 ++ dlls/ns/ParticleManager.cpp | 2 +- dlls/ns/TitleManager.cpp | 2 +- dlls/ns/natives/memberfuncs.cpp | 4 ++-- dlls/ns/natives/particles.cpp | 4 ++-- dlls/ns/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/ns/sdk/amxxmodule.h | 2 ++ dlls/nvault/NVault.cpp | 4 ---- dlls/nvault/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/nvault/sdk/amxxmodule.h | 2 ++ dlls/regex/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/regex/sdk/amxxmodule.h | 2 ++ dlls/sockets/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/sockets/sdk/amxxmodule.h | 2 ++ dlls/sqlite/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/sqlite/sdk/amxxmodule.h | 2 ++ dlls/sqlite/sqlitepp/SqliteDriver.cpp | 7 ++----- dlls/sqlite/sqlitepp/SqliteQuery.cpp | 9 ++------- dlls/tfcx/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/tfcx/sdk/amxxmodule.h | 2 ++ dlls/ts/tsfun/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/ts/tsfun/sdk/amxxmodule.h | 2 ++ dlls/ts/tsx/sdk/amxxmodule.cpp | 18 ++++++++++++++++++ dlls/ts/tsx/sdk/amxxmodule.h | 2 ++ public/memtools/MemoryUtils.cpp | 5 ++--- 61 files changed, 417 insertions(+), 72 deletions(-) diff --git a/amxmodx/CLang.cpp b/amxmodx/CLang.cpp index 6b04a52b..d51f212c 100755 --- a/amxmodx/CLang.cpp +++ b/amxmodx/CLang.cpp @@ -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 diff --git a/amxmodx/amx.cpp b/amxmodx/amx.cpp index f0a9ad1d..1a4c8724 100755 --- a/amxmodx/amx.cpp +++ b/amxmodx/amx.cpp @@ -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; diff --git a/amxmodx/libraries.cpp b/amxmodx/libraries.cpp index 5930e26d..681d9e03 100644 --- a/amxmodx/libraries.cpp +++ b/amxmodx/libraries.cpp @@ -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; diff --git a/amxmodx/sdk/amxxmodule.cpp b/amxmodx/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/amxmodx/sdk/amxxmodule.cpp +++ b/amxmodx/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/amxmodx/sdk/amxxmodule.h b/amxmodx/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/amxmodx/sdk/amxxmodule.h +++ b/amxmodx/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/cstrike/cstrike/sdk/amxxmodule.cpp b/dlls/cstrike/cstrike/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/cstrike/cstrike/sdk/amxxmodule.cpp +++ b/dlls/cstrike/cstrike/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/cstrike/cstrike/sdk/amxxmodule.h b/dlls/cstrike/cstrike/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/cstrike/cstrike/sdk/amxxmodule.h +++ b/dlls/cstrike/cstrike/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/cstrike/csx/WinCSX/amxxmodule.h b/dlls/cstrike/csx/WinCSX/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/cstrike/csx/WinCSX/amxxmodule.h +++ b/dlls/cstrike/csx/WinCSX/amxxmodule.h @@ -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__ diff --git a/dlls/cstrike/csx/sdk/amxxmodule.cpp b/dlls/cstrike/csx/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/cstrike/csx/sdk/amxxmodule.cpp +++ b/dlls/cstrike/csx/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/cstrike/csx/sdk/amxxmodule.h b/dlls/cstrike/csx/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/cstrike/csx/sdk/amxxmodule.h +++ b/dlls/cstrike/csx/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/dod/dodfun/sdk/amxxmodule.cpp b/dlls/dod/dodfun/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/dod/dodfun/sdk/amxxmodule.cpp +++ b/dlls/dod/dodfun/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/dod/dodfun/sdk/amxxmodule.h b/dlls/dod/dodfun/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/dod/dodfun/sdk/amxxmodule.h +++ b/dlls/dod/dodfun/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/dod/dodx/sdk/amxxmodule.cpp b/dlls/dod/dodx/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/dod/dodx/sdk/amxxmodule.cpp +++ b/dlls/dod/dodx/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/dod/dodx/sdk/amxxmodule.h b/dlls/dod/dodx/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/dod/dodx/sdk/amxxmodule.h +++ b/dlls/dod/dodx/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/engine/engine.cpp b/dlls/engine/engine.cpp index 3e147c74..75f8ccc9 100755 --- a/dlls/engine/engine.cpp +++ b/dlls/engine/engine.cpp @@ -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]); } diff --git a/dlls/engine/sdk/amxxmodule.cpp b/dlls/engine/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/engine/sdk/amxxmodule.cpp +++ b/dlls/engine/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/engine/sdk/amxxmodule.h b/dlls/engine/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/engine/sdk/amxxmodule.h +++ b/dlls/engine/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/fakemeta/pev.cpp b/dlls/fakemeta/pev.cpp index 5d41be5c..16f66f68 100755 --- a/dlls/fakemeta/pev.cpp +++ b/dlls/fakemeta/pev.cpp @@ -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); } diff --git a/dlls/fakemeta/sdk/amxxmodule.cpp b/dlls/fakemeta/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/fakemeta/sdk/amxxmodule.cpp +++ b/dlls/fakemeta/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/fakemeta/sdk/amxxmodule.h b/dlls/fakemeta/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/fakemeta/sdk/amxxmodule.h +++ b/dlls/fakemeta/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/fun/sdk/amxxmodule.cpp b/dlls/fun/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/fun/sdk/amxxmodule.cpp +++ b/dlls/fun/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/fun/sdk/amxxmodule.h b/dlls/fun/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/fun/sdk/amxxmodule.h +++ b/dlls/fun/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/geoip/geoip_main.cpp b/dlls/geoip/geoip_main.cpp index 61344c22..9f838f49 100644 --- a/dlls/geoip/geoip_main.cpp +++ b/dlls/geoip/geoip_main.cpp @@ -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); diff --git a/dlls/geoip/geoip_natives.cpp b/dlls/geoip/geoip_natives.cpp index 24785aa3..f55f8e1e 100755 --- a/dlls/geoip/geoip_natives.cpp +++ b/dlls/geoip/geoip_natives.cpp @@ -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); diff --git a/dlls/geoip/geoip_util.h b/dlls/geoip/geoip_util.h index c6c19909..d06e4daf 100644 --- a/dlls/geoip/geoip_util.h +++ b/dlls/geoip/geoip_util.h @@ -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); diff --git a/dlls/geoip/sdk/amxxmodule.cpp b/dlls/geoip/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/geoip/sdk/amxxmodule.cpp +++ b/dlls/geoip/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/geoip/sdk/amxxmodule.h b/dlls/geoip/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/geoip/sdk/amxxmodule.h +++ b/dlls/geoip/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/hamsandwich/config_parser.cpp b/dlls/hamsandwich/config_parser.cpp index 0d01999c..d10580d0 100644 --- a/dlls/hamsandwich/config_parser.cpp +++ b/dlls/hamsandwich/config_parser.cpp @@ -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) { diff --git a/dlls/hamsandwich/ham_utils.h b/dlls/hamsandwich/ham_utils.h index 2f1f9d70..a161aa96 100644 --- a/dlls/hamsandwich/ham_utils.h +++ b/dlls/hamsandwich/ham_utils.h @@ -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; \ } diff --git a/dlls/hamsandwich/hook.h b/dlls/hamsandwich/hook.h index 1bce3272..68949a00 100644 --- a/dlls/hamsandwich/hook.h +++ b/dlls/hamsandwich/hook.h @@ -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() diff --git a/dlls/hamsandwich/hook_native.cpp b/dlls/hamsandwich/hook_native.cpp index 748c2406..c761b3be 100644 --- a/dlls/hamsandwich/hook_native.cpp +++ b/dlls/hamsandwich/hook_native.cpp @@ -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); diff --git a/dlls/hamsandwich/sdk/amxxmodule.cpp b/dlls/hamsandwich/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100644 --- a/dlls/hamsandwich/sdk/amxxmodule.cpp +++ b/dlls/hamsandwich/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/hamsandwich/sdk/amxxmodule.h b/dlls/hamsandwich/sdk/amxxmodule.h index 6a760b25..8cb820fa 100644 --- a/dlls/hamsandwich/sdk/amxxmodule.h +++ b/dlls/hamsandwich/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/mysqlx/mysql/MysqlDriver.cpp b/dlls/mysqlx/mysql/MysqlDriver.cpp index 3ef7b201..8e422fc0 100644 --- a/dlls/mysqlx/mysql/MysqlDriver.cpp +++ b/dlls/mysqlx/mysql/MysqlDriver.cpp @@ -11,16 +11,10 @@ // MySQL Module // -#include -#include +#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; } diff --git a/dlls/mysqlx/mysql/MysqlQuery.cpp b/dlls/mysqlx/mysql/MysqlQuery.cpp index 60fa427f..f9216ffd 100644 --- a/dlls/mysqlx/mysql/MysqlQuery.cpp +++ b/dlls/mysqlx/mysql/MysqlQuery.cpp @@ -11,16 +11,11 @@ // MySQL Module // -#include -#include +#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 diff --git a/dlls/mysqlx/sdk/amxxmodule.cpp b/dlls/mysqlx/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/mysqlx/sdk/amxxmodule.cpp +++ b/dlls/mysqlx/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/mysqlx/sdk/amxxmodule.h b/dlls/mysqlx/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/mysqlx/sdk/amxxmodule.h +++ b/dlls/mysqlx/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/ns/ParticleManager.cpp b/dlls/ns/ParticleManager.cpp index 2996b5f7..0519f026 100644 --- a/dlls/ns/ParticleManager.cpp +++ b/dlls/ns/ParticleManager.cpp @@ -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) diff --git a/dlls/ns/TitleManager.cpp b/dlls/ns/TitleManager.cpp index e9a77641..ba0ee1e5 100644 --- a/dlls/ns/TitleManager.cpp +++ b/dlls/ns/TitleManager.cpp @@ -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"); diff --git a/dlls/ns/natives/memberfuncs.cpp b/dlls/ns/natives/memberfuncs.cpp index a5ad8133..def4f8c6 100644 --- a/dlls/ns/natives/memberfuncs.cpp +++ b/dlls/ns/natives/memberfuncs.cpp @@ -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); diff --git a/dlls/ns/natives/particles.cpp b/dlls/ns/natives/particles.cpp index 7d4a15bb..45c1d810 100644 --- a/dlls/ns/natives/particles.cpp +++ b/dlls/ns/natives/particles.cpp @@ -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(STRING(reinterpret_cast(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(STRING(reinterpret_cast(params[1])->v.classname)); kvd.szKeyName=name; diff --git a/dlls/ns/sdk/amxxmodule.cpp b/dlls/ns/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/ns/sdk/amxxmodule.cpp +++ b/dlls/ns/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/ns/sdk/amxxmodule.h b/dlls/ns/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/ns/sdk/amxxmodule.h +++ b/dlls/ns/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/nvault/NVault.cpp b/dlls/nvault/NVault.cpp index 95517fbb..fe50f239 100755 --- a/dlls/nvault/NVault.cpp +++ b/dlls/nvault/NVault.cpp @@ -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? diff --git a/dlls/nvault/sdk/amxxmodule.cpp b/dlls/nvault/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/nvault/sdk/amxxmodule.cpp +++ b/dlls/nvault/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/nvault/sdk/amxxmodule.h b/dlls/nvault/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/nvault/sdk/amxxmodule.h +++ b/dlls/nvault/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/regex/sdk/amxxmodule.cpp b/dlls/regex/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/regex/sdk/amxxmodule.cpp +++ b/dlls/regex/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/regex/sdk/amxxmodule.h b/dlls/regex/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/regex/sdk/amxxmodule.h +++ b/dlls/regex/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/sockets/sdk/amxxmodule.cpp b/dlls/sockets/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/sockets/sdk/amxxmodule.cpp +++ b/dlls/sockets/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/sockets/sdk/amxxmodule.h b/dlls/sockets/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/sockets/sdk/amxxmodule.h +++ b/dlls/sockets/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/sqlite/sdk/amxxmodule.cpp b/dlls/sqlite/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/sqlite/sdk/amxxmodule.cpp +++ b/dlls/sqlite/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/sqlite/sdk/amxxmodule.h b/dlls/sqlite/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/sqlite/sdk/amxxmodule.h +++ b/dlls/sqlite/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/sqlite/sqlitepp/SqliteDriver.cpp b/dlls/sqlite/sqlitepp/SqliteDriver.cpp index ab60b921..f4d8e74f 100644 --- a/dlls/sqlite/sqlitepp/SqliteDriver.cpp +++ b/dlls/sqlite/sqlitepp/SqliteDriver.cpp @@ -11,15 +11,12 @@ // SQLite Module // -#include -#include +#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 #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; diff --git a/dlls/sqlite/sqlitepp/SqliteQuery.cpp b/dlls/sqlite/sqlitepp/SqliteQuery.cpp index 61e3e19e..d04b7fff 100644 --- a/dlls/sqlite/sqlitepp/SqliteQuery.cpp +++ b/dlls/sqlite/sqlitepp/SqliteQuery.cpp @@ -11,16 +11,11 @@ // SQLite Module // -#include -#include +#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; diff --git a/dlls/tfcx/sdk/amxxmodule.cpp b/dlls/tfcx/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/tfcx/sdk/amxxmodule.cpp +++ b/dlls/tfcx/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/tfcx/sdk/amxxmodule.h b/dlls/tfcx/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/tfcx/sdk/amxxmodule.h +++ b/dlls/tfcx/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/ts/tsfun/sdk/amxxmodule.cpp b/dlls/ts/tsfun/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/ts/tsfun/sdk/amxxmodule.cpp +++ b/dlls/ts/tsfun/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/ts/tsfun/sdk/amxxmodule.h b/dlls/ts/tsfun/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/ts/tsfun/sdk/amxxmodule.h +++ b/dlls/ts/tsfun/sdk/amxxmodule.h @@ -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__ diff --git a/dlls/ts/tsx/sdk/amxxmodule.cpp b/dlls/ts/tsx/sdk/amxxmodule.cpp index 7de02e6e..4781bbe3 100755 --- a/dlls/ts/tsx/sdk/amxxmodule.cpp +++ b/dlls/ts/tsx/sdk/amxxmodule.cpp @@ -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; + } +} diff --git a/dlls/ts/tsx/sdk/amxxmodule.h b/dlls/ts/tsx/sdk/amxxmodule.h index 6a760b25..8cb820fa 100755 --- a/dlls/ts/tsx/sdk/amxxmodule.h +++ b/dlls/ts/tsx/sdk/amxxmodule.h @@ -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__ diff --git a/public/memtools/MemoryUtils.cpp b/public/memtools/MemoryUtils.cpp index 5226c3c3..65e38636 100644 --- a/public/memtools/MemoryUtils.cpp +++ b/public/memtools/MemoryUtils.cpp @@ -28,8 +28,7 @@ */ #include "MemoryUtils.h" -#include -#include +#include "amxxmodule.h" #if defined(__linux__) #include @@ -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;