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
63 changed files with 438 additions and 79 deletions

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__