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