Fix strncpy usage in botlib
All usage of strncpy in botlib should now either set string terminator or use Q_strncpyz.
This commit is contained in:
parent
8956ab41dd
commit
c12b81a273
8 changed files with 13 additions and 14 deletions
|
@ -238,7 +238,7 @@ int AAS_LoadFiles(const char *mapname)
|
||||||
return errnum;
|
return errnum;
|
||||||
|
|
||||||
botimport.Print(PRT_MESSAGE, "loaded %s\n", aasfile);
|
botimport.Print(PRT_MESSAGE, "loaded %s\n", aasfile);
|
||||||
strncpy(aasworld.filename, aasfile, MAX_PATH);
|
Q_strncpyz(aasworld.filename, aasfile, sizeof(aasworld.filename));
|
||||||
return BLERR_NOERROR;
|
return BLERR_NOERROR;
|
||||||
} //end of the function AAS_LoadFiles
|
} //end of the function AAS_LoadFiles
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
|
@ -342,7 +342,7 @@ void BotQueueConsoleMessage(int chatstate, int type, char *message)
|
||||||
m->handle = cs->handle;
|
m->handle = cs->handle;
|
||||||
m->time = AAS_Time();
|
m->time = AAS_Time();
|
||||||
m->type = type;
|
m->type = type;
|
||||||
strncpy(m->message, message, MAX_MESSAGE_SIZE);
|
Q_strncpyz(m->message, message, MAX_MESSAGE_SIZE);
|
||||||
m->next = NULL;
|
m->next = NULL;
|
||||||
if (cs->lastmessage)
|
if (cs->lastmessage)
|
||||||
{
|
{
|
||||||
|
@ -1456,7 +1456,7 @@ int BotFindMatch(char *str, bot_match_t *match, unsigned long int context)
|
||||||
int i;
|
int i;
|
||||||
bot_matchtemplate_t *ms;
|
bot_matchtemplate_t *ms;
|
||||||
|
|
||||||
strncpy(match->string, str, MAX_MESSAGE_SIZE);
|
Q_strncpyz(match->string, str, MAX_MESSAGE_SIZE);
|
||||||
//remove any trailing enters
|
//remove any trailing enters
|
||||||
while(strlen(match->string) &&
|
while(strlen(match->string) &&
|
||||||
match->string[strlen(match->string)-1] == '\n')
|
match->string[strlen(match->string)-1] == '\n')
|
||||||
|
@ -2114,7 +2114,7 @@ bot_chat_t *BotLoadInitialChat(char *chatfile, char *chatname)
|
||||||
if (pass && ptr)
|
if (pass && ptr)
|
||||||
{
|
{
|
||||||
chattype = (bot_chattype_t *) ptr;
|
chattype = (bot_chattype_t *) ptr;
|
||||||
strncpy(chattype->name, token.string, MAX_CHATTYPE_NAME);
|
Q_strncpyz(chattype->name, token.string, MAX_CHATTYPE_NAME);
|
||||||
chattype->firstchatmessage = NULL;
|
chattype->firstchatmessage = NULL;
|
||||||
//add the chat type to the chat
|
//add the chat type to the chat
|
||||||
chattype->next = chat->types;
|
chattype->next = chat->types;
|
||||||
|
@ -2884,7 +2884,7 @@ void BotSetChatName(int chatstate, char *name, int client)
|
||||||
if (!cs) return;
|
if (!cs) return;
|
||||||
cs->client = client;
|
cs->client = client;
|
||||||
Com_Memset(cs->name, 0, sizeof(cs->name));
|
Com_Memset(cs->name, 0, sizeof(cs->name));
|
||||||
strncpy(cs->name, name, sizeof(cs->name));
|
strncpy(cs->name, name, sizeof(cs->name)-1);
|
||||||
cs->name[sizeof(cs->name)-1] = '\0';
|
cs->name[sizeof(cs->name)-1] = '\0';
|
||||||
} //end of the function BotSetChatName
|
} //end of the function BotSetChatName
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
|
@ -281,7 +281,7 @@ itemconfig_t *LoadItemConfig(char *filename)
|
||||||
LibVarSet( "max_iteminfo", "256" );
|
LibVarSet( "max_iteminfo", "256" );
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy( path, filename, MAX_PATH );
|
Q_strncpyz(path, filename, sizeof(path));
|
||||||
PC_SetBaseFolder(BOTFILESBASEFOLDER);
|
PC_SetBaseFolder(BOTFILESBASEFOLDER);
|
||||||
source = LoadSourceFile( path );
|
source = LoadSourceFile( path );
|
||||||
if( !source ) {
|
if( !source ) {
|
||||||
|
@ -314,7 +314,7 @@ itemconfig_t *LoadItemConfig(char *filename)
|
||||||
return NULL;
|
return NULL;
|
||||||
} //end if
|
} //end if
|
||||||
StripDoubleQuotes(token.string);
|
StripDoubleQuotes(token.string);
|
||||||
strncpy(ii->classname, token.string, sizeof(ii->classname)-1);
|
Q_strncpyz(ii->classname, token.string, sizeof(ii->classname));
|
||||||
if (!ReadStructure(source, &iteminfo_struct, (char *) ii))
|
if (!ReadStructure(source, &iteminfo_struct, (char *) ii))
|
||||||
{
|
{
|
||||||
FreeMemory(ic);
|
FreeMemory(ic);
|
||||||
|
@ -685,8 +685,7 @@ void BotGoalName(int number, char *name, int size)
|
||||||
{
|
{
|
||||||
if (li->number == number)
|
if (li->number == number)
|
||||||
{
|
{
|
||||||
strncpy(name, itemconfig->iteminfo[li->iteminfo].name, size-1);
|
Q_strncpyz(name, itemconfig->iteminfo[li->iteminfo].name, size);
|
||||||
name[size-1] = '\0';
|
|
||||||
return;
|
return;
|
||||||
} //end for
|
} //end for
|
||||||
} //end for
|
} //end for
|
||||||
|
|
|
@ -219,7 +219,7 @@ weaponconfig_t *LoadWeaponConfig(char *filename)
|
||||||
max_projectileinfo = 32;
|
max_projectileinfo = 32;
|
||||||
LibVarSet("max_projectileinfo", "32");
|
LibVarSet("max_projectileinfo", "32");
|
||||||
} //end if
|
} //end if
|
||||||
strncpy(path, filename, MAX_PATH);
|
Q_strncpyz(path, filename, sizeof(path));
|
||||||
PC_SetBaseFolder(BOTFILESBASEFOLDER);
|
PC_SetBaseFolder(BOTFILESBASEFOLDER);
|
||||||
source = LoadSourceFile(path);
|
source = LoadSourceFile(path);
|
||||||
if (!source)
|
if (!source)
|
||||||
|
|
|
@ -75,7 +75,7 @@ void Log_Open(char *filename)
|
||||||
botimport.Print(PRT_ERROR, "can't open the log file %s\n", filename);
|
botimport.Print(PRT_ERROR, "can't open the log file %s\n", filename);
|
||||||
return;
|
return;
|
||||||
} //end if
|
} //end if
|
||||||
strncpy(logfile.filename, filename, MAX_LOGFILENAMESIZE);
|
Q_strncpyz(logfile.filename, filename, MAX_LOGFILENAMESIZE);
|
||||||
botimport.Print(PRT_MESSAGE, "Opened log %s\n", logfile.filename);
|
botimport.Print(PRT_MESSAGE, "Opened log %s\n", logfile.filename);
|
||||||
} //end of the function Log_Create
|
} //end of the function Log_Create
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
|
|
@ -1323,7 +1323,7 @@ define_t *PC_DefineFromString(char *string)
|
||||||
script = LoadScriptMemory(string, strlen(string), "*extern");
|
script = LoadScriptMemory(string, strlen(string), "*extern");
|
||||||
//create a new source
|
//create a new source
|
||||||
Com_Memset(&src, 0, sizeof(source_t));
|
Com_Memset(&src, 0, sizeof(source_t));
|
||||||
strncpy(src.filename, "*extern", sizeof(src.filename) - 1);
|
Q_strncpyz(src.filename, "*extern", sizeof(src.filename));
|
||||||
src.scriptstack = script;
|
src.scriptstack = script;
|
||||||
#if DEFINEHASHING
|
#if DEFINEHASHING
|
||||||
src.definehash = GetClearedMemory(DEFINEHASHSIZE * sizeof(define_t *));
|
src.definehash = GetClearedMemory(DEFINEHASHSIZE * sizeof(define_t *));
|
||||||
|
|
|
@ -804,7 +804,7 @@ int PS_ReadPunctuation(script_t *script, token_t *token)
|
||||||
//if the script contains the punctuation
|
//if the script contains the punctuation
|
||||||
if (!strncmp(script->script_p, p, len))
|
if (!strncmp(script->script_p, p, len))
|
||||||
{
|
{
|
||||||
strncpy(token->string, p, MAX_TOKEN);
|
Q_strncpyz(token->string, p, MAX_TOKEN);
|
||||||
script->script_p += len;
|
script->script_p += len;
|
||||||
token->type = TT_PUNCTUATION;
|
token->type = TT_PUNCTUATION;
|
||||||
//sub type is the number of the punctuation
|
//sub type is the number of the punctuation
|
||||||
|
|
|
@ -221,7 +221,7 @@ int ReadString(source_t *source, fielddef_t *fd, void *p)
|
||||||
//remove the double quotes
|
//remove the double quotes
|
||||||
StripDoubleQuotes(token.string);
|
StripDoubleQuotes(token.string);
|
||||||
//copy the string
|
//copy the string
|
||||||
strncpy((char *) p, token.string, MAX_STRINGFIELD);
|
strncpy((char *) p, token.string, MAX_STRINGFIELD-1);
|
||||||
//make sure the string is closed with a zero
|
//make sure the string is closed with a zero
|
||||||
((char *)p)[MAX_STRINGFIELD-1] = '\0';
|
((char *)p)[MAX_STRINGFIELD-1] = '\0';
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue