fixed possible overflow cases

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40657
This commit is contained in:
Borja Ferrer 2007-03-19 19:19:41 +00:00
parent 1ced2210ed
commit 862f25b223
4 changed files with 10 additions and 3 deletions

View File

@ -158,7 +158,7 @@ void RootConsoleMenu::DrawGenericOption(const char *cmd, const char *text)
char buffer[255]; char buffer[255];
size_t len, cmdlen = strlen(cmd); size_t len, cmdlen = strlen(cmd);
len = snprintf(buffer, sizeof(buffer), " %s", cmd); len = UTIL_Format(buffer, sizeof(buffer), " %s", cmd);
if (cmdlen < 16) if (cmdlen < 16)
{ {
size_t num = 16 - cmdlen; size_t num = 16 - cmdlen;

View File

@ -890,7 +890,13 @@ size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...)
size_t len = vsnprintf(buffer, maxlength, fmt, ap); size_t len = vsnprintf(buffer, maxlength, fmt, ap);
va_end(ap); va_end(ap);
return (len >= maxlength) ? (maxlength - 1) : len; if (len >= maxlength)
{
buffer[maxlength - 1] = '\0';
return (maxlength - 1);
} else {
return len;
}
} }
char *sm_strdup(const char *str) char *sm_strdup(const char *str)

View File

@ -305,7 +305,7 @@ size_t LibrarySystem::PathFormat(char *buffer, size_t len, const char *fmt, ...)
size_t mylen = vsnprintf(buffer, len, fmt, ap); size_t mylen = vsnprintf(buffer, len, fmt, ap);
va_end(ap); va_end(ap);
mylen = (mylen >= len) ? (len - 1) : mylen; mylen = (mylen >= len) ? len : mylen;
for (size_t i=0; i<mylen; i++) for (size_t i=0; i<mylen; i++)
{ {

View File

@ -109,6 +109,7 @@ forward OnGameFrame();
* Called when the map is loaded and configs have been parsed. * Called when the map is loaded and configs have been parsed.
* Note that commands are processed per-frame, and thus config * Note that commands are processed per-frame, and thus config
* files may not be fully loaded until a few seconds later. * files may not be fully loaded until a few seconds later.
* This function will be called on each mapchange.
*/ */
forward OnServerLoad(); forward OnServerLoad();