Merge pull request #110 from Arkshine/replace-more-snprintf
Replace more snprintf by UTIL_Format.
This commit is contained in:
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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