* Replace a lot of strncat(dst, src, sizeof(dst) - strlen(dst) - 1) calls with the less bloated strlcat(dst, src, sizeof(dst)) form
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@2637 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
86328025d2
commit
bd37e62cb2
|
@ -111,10 +111,10 @@ void debug_callback_win32debug( void ** data, const char * outputBuffer )
|
|||
{
|
||||
char tmpStr[MAX_LEN_LOG_LINE];
|
||||
|
||||
strncpy(tmpStr, outputBuffer, sizeof(tmpStr));
|
||||
strlcpy(tmpStr, outputBuffer, sizeof(tmpStr));
|
||||
if (!strchr(tmpStr, '\n'))
|
||||
{
|
||||
strncat(tmpStr, "\n", sizeof(tmpStr) - strlen(tmpStr) - 1);
|
||||
strlcat(tmpStr, "\n", sizeof(tmpStr));
|
||||
}
|
||||
|
||||
OutputDebugStringA( tmpStr );
|
||||
|
|
|
@ -41,22 +41,18 @@ static LONG WINAPI windowsExceptionHandler(PEXCEPTION_POINTERS pExceptionInfo)
|
|||
// Write to temp dir, to support unprivileged users
|
||||
if (!GetTempPathA( PATH_MAX, miniDumpPath ))
|
||||
{
|
||||
strncpy(miniDumpPath, "c:\\temp\\", sizeof(miniDumpPath));
|
||||
// Guarantee to nul-terminate
|
||||
miniDumpPath[sizeof(miniDumpPath) - 1] = '\0';
|
||||
strlcpy(miniDumpPath, "c:\\temp\\", sizeof(miniDumpPath));
|
||||
}
|
||||
|
||||
// Append the filename
|
||||
strncat(miniDumpPath, "warzone2100.mdmp", sizeof(miniDumpPath) - strlen(miniDumpPath) - 1);
|
||||
strlcat(miniDumpPath, "warzone2100.mdmp", sizeof(miniDumpPath));
|
||||
|
||||
/*
|
||||
Alternative:
|
||||
GetModuleFileName( NULL, miniDumpPath, MAX_PATH );
|
||||
|
||||
// Append extension
|
||||
strncat(miniDumpPath, ".mdmp", sizeof(miniDumpPath));
|
||||
// Guarantee to nul-terminate
|
||||
miniDumpPath[sizeof(miniDumpPath) - 1] = '\0';
|
||||
strlcat(miniDumpPath, ".mdmp", sizeof(miniDumpPath));
|
||||
*/
|
||||
|
||||
if ( MessageBoxA( NULL, "Warzone crashed unexpectedly, would you like to save a diagnostic file?", applicationName, MB_YESNO ) == IDYES )
|
||||
|
@ -625,9 +621,9 @@ void setupExceptionHandler(const char * programCommand)
|
|||
sysInfoValid = (uname(&sysInfo) == 0);
|
||||
|
||||
time_t currentTime = time(NULL);
|
||||
strncpy( executionDate, ctime(¤tTime), MAX_DATE_STRING );
|
||||
strlcpy(executionDate, ctime(¤tTime), sizeof(executionDate));
|
||||
|
||||
snprintf( programPID, MAX_PID_STRING, "%i", getpid() );
|
||||
snprintf(programPID, sizeof(programPID), "%i", getpid());
|
||||
|
||||
setFatalSignalHandler(posixExceptionHandler);
|
||||
#endif // WZ_OS_*
|
||||
|
|
|
@ -93,7 +93,7 @@ void resShutDown(void)
|
|||
// set the base resource directory
|
||||
void resSetBaseDir(char *pResDir)
|
||||
{
|
||||
strncpy(aResDir, pResDir, PATH_MAX - 1);
|
||||
strlcpy(aResDir, pResDir, sizeof(aResDir));
|
||||
}
|
||||
|
||||
/* Parse the res file */
|
||||
|
@ -103,9 +103,7 @@ BOOL resLoad(const char *pResFile, SDWORD blockID,
|
|||
char *pBuffer;
|
||||
UDWORD size;
|
||||
|
||||
strncpy(aCurrResDir, aResDir, sizeof(aCurrResDir));
|
||||
// Guarantee to nul-terminate
|
||||
aCurrResDir[sizeof(aCurrResDir) - 1] = '\0';
|
||||
strlcpy(aCurrResDir, aResDir, sizeof(aCurrResDir));
|
||||
|
||||
// Note the block id number
|
||||
resBlockID = blockID;
|
||||
|
@ -158,8 +156,7 @@ static RES_TYPE* resAlloc(const char *pType)
|
|||
}
|
||||
|
||||
// setup the structure
|
||||
strncpy(psT->aType, pType, RESTYPE_MAXCHAR - 1);
|
||||
psT->aType[RESTYPE_MAXCHAR - 1] = 0;
|
||||
strlcpy(psT->aType, pType, sizeof(psT->aType));
|
||||
|
||||
psT->HashedType=HashString(psT->aType); // store a hased version for super speed !
|
||||
|
||||
|
@ -243,8 +240,7 @@ const char *GetLastResourceFilename(void)
|
|||
*/
|
||||
void SetLastResourceFilename(const char *pName)
|
||||
{
|
||||
strncpy(LastResourceFilename, pName, PATH_MAX-1);
|
||||
LastResourceFilename[PATH_MAX-1] = '\0';
|
||||
strlcpy(LastResourceFilename, pName, sizeof(LastResourceFilename));
|
||||
}
|
||||
|
||||
|
||||
|
@ -387,8 +383,7 @@ static WZ_DECL_CONST const char* getLanguage(void)
|
|||
return language; // Return empty string on errors
|
||||
}
|
||||
|
||||
strncpy(language, localeName, sizeof(language));
|
||||
language[sizeof(language) - 1] = '\0'; // be sure to have a 0-terminated string
|
||||
strlcpy(language, localeName, sizeof(language));
|
||||
|
||||
delim = strchr(language, '_');
|
||||
|
||||
|
@ -485,11 +480,8 @@ BOOL resLoadFile(const char *pType, const char *pFile)
|
|||
debug(LOG_ERROR, "resLoadFile: Filename too long!! %s%s", aCurrResDir, pFile);
|
||||
return FALSE;
|
||||
}
|
||||
strncpy(aFileName, aCurrResDir, sizeof(aFileName));
|
||||
// Guarantee to nul-terminate
|
||||
aFileName[sizeof(aFileName) - 1] = '\0';
|
||||
|
||||
strncat(aFileName, pFile, sizeof(aFileName) - strlen(aFileName) - 1);
|
||||
strlcpy(aFileName, aCurrResDir, sizeof(aFileName));
|
||||
strlcat(aFileName, pFile, sizeof(aFileName));
|
||||
|
||||
makeLocaleFile(aFileName); // check for translated file
|
||||
|
||||
|
|
|
@ -70,12 +70,12 @@ static void print_nested_groups(struct define *group)
|
|||
if (parent != NULL)
|
||||
{
|
||||
snprintf(groupdesc, PRNG_LEN, "\nNested inside element %d", (int)parent->element);
|
||||
strncat(errbuf, groupdesc, sizeof(errbuf) - strlen(errbuf) - 1);
|
||||
strlcat(errbuf, groupdesc, sizeof(errbuf));
|
||||
print_nested_groups(parent);
|
||||
}
|
||||
if (parent == NULL)
|
||||
{
|
||||
strncat(errbuf, "\n", sizeof(errbuf) - strlen(errbuf) - 1);
|
||||
strlcat(errbuf, "\n", sizeof(errbuf));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -737,7 +737,7 @@ iIMDShape *iV_ProcessIMD( const char **ppFileData, const char *FileDataEnd )
|
|||
debug(LOG_ERROR, "iV_ProcessIMD %s: only png textures supported", pFileName);
|
||||
return NULL;
|
||||
}
|
||||
strncat(texfile, ".png", sizeof(texfile) - strlen(texfile) - 1);
|
||||
strlcat(texfile, ".png", sizeof(texfile));
|
||||
|
||||
pie_MakeTexPageName(texfile);
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ static inline void iV_printFontList()
|
|||
char prBuffer[1024];
|
||||
snprintf(prBuffer, sizeof(prBuffer), "Font #%d : %s ", font, (const char*)glcGetFontc(font, GLC_FAMILY));
|
||||
prBuffer[sizeof(prBuffer) - 1] = 0;
|
||||
strncat(prBuffer, glcGetFontFace(font), sizeof(prBuffer) - strlen(prBuffer) - 1);
|
||||
strlcat(prBuffer, glcGetFontFace(font), sizeof(prBuffer));
|
||||
debug(LOG_NEVER, prBuffer);
|
||||
}
|
||||
}
|
||||
|
@ -545,7 +545,7 @@ UDWORD iV_DrawFormattedText(const char* String, UDWORD x, UDWORD y, UDWORD Width
|
|||
FWord[i] = 0;
|
||||
|
||||
// And add it to the output string.
|
||||
strncat(FString, FWord, sizeof(FString) - strlen(FString) - 1);
|
||||
strlcat(FString, FWord, sizeof(FString));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -745,9 +745,7 @@ BOOL stackBinaryOp(OPCODE opcode)
|
|||
break;
|
||||
|
||||
case VAL_STRING:
|
||||
strncpy(tempstr1, psV1->v.sval, sizeof(tempstr1));
|
||||
// Guarantee to nul-terminate
|
||||
tempstr1[sizeof(tempstr1) - 1] = '\0';
|
||||
strlcpy(tempstr1, psV1->v.sval, sizeof(tempstr1));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -778,9 +776,7 @@ BOOL stackBinaryOp(OPCODE opcode)
|
|||
break;
|
||||
|
||||
case VAL_STRING:
|
||||
strncpy(tempstr2, psV2->v.sval, sizeof(tempstr2));
|
||||
// Guarantee to nul-terminate
|
||||
tempstr2[sizeof(tempstr2) - 1] = '\0';
|
||||
strlcpy(tempstr2, psV2->v.sval, sizeof(tempstr2));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -789,7 +785,7 @@ BOOL stackBinaryOp(OPCODE opcode)
|
|||
break;
|
||||
}
|
||||
|
||||
strncat(tempstr1, tempstr2, sizeof(tempstr1) - strlen(tempstr1) - 1);
|
||||
strlcat(tempstr1, tempstr2, sizeof(tempstr1));
|
||||
|
||||
strcpy(psV1->v.sval,tempstr1); //Assign
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ BOOL ParseCommandLine(int argc, char** argv)
|
|||
debug( LOG_ERROR, "Unrecognised datadir\n" );
|
||||
return FALSE;
|
||||
}
|
||||
strncpy(datadir, token, sizeof(datadir));
|
||||
strlcpy(datadir, token, sizeof(datadir));
|
||||
}
|
||||
else if ( strcasecmp(tokenType, "--cheat") == 0 )
|
||||
{
|
||||
|
|
|
@ -720,7 +720,7 @@ static BOOL dataTexPageLoad(const char *fileName, void **ppData)
|
|||
char texpage[PATH_MAX] = {'\0'};
|
||||
|
||||
// This hackery is needed, because fileName will include the directory name, whilst the LastResourceFilename will not, and we need a short name to identify the texpage
|
||||
strncpy(texpage, GetLastResourceFilename(), PATH_MAX);
|
||||
strlcpy(texpage, GetLastResourceFilename(), sizeof(texpage));
|
||||
|
||||
pie_MakeTexPageName(texpage);
|
||||
dataImageLoad(fileName, ppData);
|
||||
|
|
16
src/design.c
16
src/design.c
|
@ -1081,7 +1081,7 @@ BOOL intAddTemplateButtons(UDWORD formID, UDWORD formWidth, UDWORD formHeight,
|
|||
|
||||
|
||||
// On the playstation the tips are additionaly setup when they are displayed ... because we only have one text name buffer
|
||||
strncpy(aButText, getTemplateName( psTempl ), DES_COMPBUTMAXCHAR);
|
||||
strlcpy(aButText, getTemplateName( psTempl ), sizeof(aButText));
|
||||
sButInit.pTip = getTemplateName(psTempl);
|
||||
|
||||
BufferID = GetStatBuffer();
|
||||
|
@ -2394,7 +2394,7 @@ static BOOL intAddComponentButtons(COMP_BASE_STATS *psStats, UDWORD size,
|
|||
}
|
||||
|
||||
/* Set the tip and add the button */
|
||||
strncpy(aButText, getStatName(psCurrStats), DES_COMPBUTMAXCHAR);
|
||||
strlcpy(aButText, getStatName(psCurrStats), sizeof(aButText));
|
||||
sButInit.pTip = getStatName(psCurrStats);
|
||||
|
||||
BufferID = GetObjectBuffer();
|
||||
|
@ -2594,7 +2594,7 @@ static BOOL intAddExtraSystemButtons(UDWORD sensorIndex, UDWORD ecmIndex,
|
|||
}
|
||||
|
||||
// Set the tip and add the button
|
||||
strncpy(aButText, getStatName(psCurrStats), DES_COMPBUTMAXCHAR);
|
||||
strlcpy(aButText, getStatName(psCurrStats), sizeof(aButText));
|
||||
sButInit.pTip = getStatName(psCurrStats);
|
||||
|
||||
BufferID = sButInit.id-IDDES_EXTRASYSSTART;
|
||||
|
@ -3695,7 +3695,7 @@ void intProcessDesign(UDWORD id)
|
|||
{
|
||||
/* Set the new template */
|
||||
memcpy(&sCurrDesign, psTempl, sizeof(DROID_TEMPLATE));
|
||||
strncpy( aCurrName, getTemplateName(psTempl), WIDG_MAXSTR-1);
|
||||
strlcpy(aCurrName, getTemplateName(psTempl), sizeof(aCurrName));
|
||||
|
||||
/* reveal body and propulsion component buttons */
|
||||
widgReveal( psWScreen, IDDES_BODYBUTTON );
|
||||
|
@ -4229,9 +4229,8 @@ void intProcessDesign(UDWORD id)
|
|||
break;
|
||||
/* The name edit box */
|
||||
case IDDES_NAMEBOX:
|
||||
strncpy(sCurrDesign.aName, widgGetString(psWScreen, IDDES_NAMEBOX),
|
||||
DROID_MAXNAME);
|
||||
strncpy(aCurrName, sCurrDesign.aName,WIDG_MAXSTR-1);
|
||||
strlcpy(sCurrDesign.aName, widgGetString(psWScreen, IDDES_NAMEBOX), sizeof(sCurrDesign.aName));
|
||||
strlcpy(aCurrName, sCurrDesign.aName, sizeof(aCurrName));
|
||||
break;
|
||||
case IDDES_BIN:
|
||||
/* Find the template for the current button */
|
||||
|
@ -4930,8 +4929,7 @@ static BOOL saveTemplate(void)
|
|||
|
||||
/* Copy the template */
|
||||
memcpy(psTempl, &sCurrDesign, sizeof(DROID_TEMPLATE));
|
||||
strncpy(psTempl->aName, aCurrName, DROID_MAXNAME);
|
||||
psTempl->aName[DROID_MAXNAME - 1] = 0;
|
||||
strlcpy(psTempl->aName, aCurrName, sizeof(psTempl->aName));
|
||||
|
||||
/* Now update the droid template form */
|
||||
widgDelete(psWScreen, IDDES_TEMPLFORM);
|
||||
|
|
|
@ -4278,8 +4278,7 @@ char *droidGetName(DROID *psDroid)
|
|||
//
|
||||
void droidSetName(DROID *psDroid,const char *pName)
|
||||
{
|
||||
strncpy(psDroid->aName,pName, DROID_MAXNAME);
|
||||
psDroid->aName[DROID_MAXNAME-1] = 0;
|
||||
strlcpy(psDroid->aName, pName, sizeof(psDroid->aName));
|
||||
}
|
||||
|
||||
|
||||
|
|
20
src/game.c
20
src/game.c
|
@ -5340,8 +5340,7 @@ static DROID* buildDroidFromSaveDroidV11(SAVE_DROID_V11* psSaveDroid)
|
|||
//set up the template
|
||||
//copy the values across
|
||||
|
||||
strncpy(psTemplate->aName, psSaveDroid->name, DROID_MAXNAME);
|
||||
psTemplate->aName[DROID_MAXNAME-1]=0;
|
||||
strlcpy(psTemplate->aName, psSaveDroid->name, sizeof(psTemplate->aName));
|
||||
//ignore the first comp - COMP_UNKNOWN
|
||||
found = TRUE;
|
||||
for (i=1; i < DROID_MAXCOMP; i++)
|
||||
|
@ -5448,8 +5447,7 @@ static DROID* buildDroidFromSaveDroidV19(SAVE_DROID_V18* psSaveDroid, UDWORD ver
|
|||
//set up the template
|
||||
//copy the values across
|
||||
|
||||
strncpy(psTemplate->aName, psSaveDroid->name, DROID_MAXNAME);
|
||||
psTemplate->aName[DROID_MAXNAME-1]=0;
|
||||
strlcpy(psTemplate->aName, psSaveDroid->name, sizeof(psTemplate->aName));
|
||||
|
||||
//ignore the first comp - COMP_UNKNOWN
|
||||
found = TRUE;
|
||||
|
@ -5685,8 +5683,7 @@ static DROID* buildDroidFromSaveDroid(SAVE_DROID* psSaveDroid, UDWORD version)
|
|||
//set up the template
|
||||
//copy the values across
|
||||
|
||||
strncpy(psTemplate->aName, psSaveDroid->name, DROID_MAXNAME);
|
||||
psTemplate->aName[DROID_MAXNAME-1]=0;
|
||||
strlcpy(psTemplate->aName, psSaveDroid->name, sizeof(psTemplate->aName));
|
||||
//ignore the first comp - COMP_UNKNOWN
|
||||
found = TRUE;
|
||||
for (i=1; i < DROID_MAXCOMP; i++)
|
||||
|
@ -9020,8 +9017,7 @@ BOOL loadSaveTemplateV7(char *pFileData, UDWORD filesize, UDWORD numTemplates)
|
|||
//copy the values across
|
||||
|
||||
psTemplate->pName = NULL;
|
||||
strncpy(psTemplate->aName, psSaveTemplate->name, DROID_MAXNAME);
|
||||
psTemplate->aName[DROID_MAXNAME-1]=0;
|
||||
strlcpy(psTemplate->aName, psSaveTemplate->name, sizeof(psTemplate->aName));
|
||||
|
||||
psTemplate->ref = psSaveTemplate->ref;
|
||||
psTemplate->droidType = psSaveTemplate->droidType;
|
||||
|
@ -9153,9 +9149,7 @@ BOOL loadSaveTemplateV14(char *pFileData, UDWORD filesize, UDWORD numTemplates)
|
|||
//copy the values across
|
||||
|
||||
psTemplate->pName = NULL;
|
||||
strncpy(psTemplate->aName, psSaveTemplate->name, DROID_MAXNAME);
|
||||
psTemplate->aName[DROID_MAXNAME-1]=0;
|
||||
|
||||
strlcpy(psTemplate->aName, psSaveTemplate->name, sizeof(psTemplate->aName));
|
||||
|
||||
psTemplate->ref = psSaveTemplate->ref;
|
||||
psTemplate->droidType = psSaveTemplate->droidType;
|
||||
|
@ -9310,9 +9304,7 @@ BOOL loadSaveTemplateV(char *pFileData, UDWORD filesize, UDWORD numTemplates)
|
|||
//copy the values across
|
||||
|
||||
psTemplate->pName = NULL;
|
||||
strncpy(psTemplate->aName, psSaveTemplate->name, DROID_MAXNAME);
|
||||
psTemplate->aName[DROID_MAXNAME-1]=0;
|
||||
|
||||
strlcpy(psTemplate->aName, psSaveTemplate->name, sizeof(psTemplate->aName));
|
||||
|
||||
psTemplate->ref = psSaveTemplate->ref;
|
||||
psTemplate->droidType = psSaveTemplate->droidType;
|
||||
|
|
|
@ -420,7 +420,7 @@ void intUpdateQuantity(WIDGET *psWidget, W_CONTEXT *psContext)
|
|||
/*Quantity = StructureGetFactory(Structure)->quantity;
|
||||
if (Quantity == NON_STOP_PRODUCTION)
|
||||
{
|
||||
strncpy(Label->aText, "*", sizeof(Label->aText));
|
||||
strlcpy(Label->aText, "*", sizeof(Label->aText));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -544,11 +544,13 @@ void intAddLoopQuantity(WIDGET *psWidget, W_CONTEXT *psContext)
|
|||
|
||||
if (psFactory->quantity == INFINITE_PRODUCTION)
|
||||
{
|
||||
strncpy(Label->aText, "∞", sizeof(Label->aText));
|
||||
strlcpy(Label->aText, "∞", sizeof(Label->aText));
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(Label->aText, sizeof(Label->aText), "%02u", psFactory->quantity + DEFAULT_LOOP);
|
||||
// Guarantee to nul-terminate
|
||||
Label->aText[sizeof(Label->aText) - 1] = '\0';
|
||||
}
|
||||
Label->style &= ~WIDG_HIDDEN;
|
||||
}
|
||||
|
|
51
src/main.c
51
src/main.c
|
@ -156,10 +156,10 @@ void addSubdirs( const char * basedir, const char * subdir, const BOOL appendToP
|
|||
#endif // DEBUG
|
||||
if( !checkList || inList( checkList, *i ) )
|
||||
{
|
||||
strcpy( tmpstr, basedir );
|
||||
strcat( tmpstr, subdir );
|
||||
strcat( tmpstr, PHYSFS_getDirSeparator() );
|
||||
strcat( tmpstr, *i );
|
||||
strlcpy(tmpstr, basedir, sizeof(tmpstr));
|
||||
strlcat(tmpstr, subdir, sizeof(tmpstr));
|
||||
strlcat(tmpstr, PHYSFS_getDirSeparator(), sizeof(tmpstr));
|
||||
strlcat(tmpstr, *i, sizeof(tmpstr));
|
||||
#ifdef DEBUG
|
||||
debug( LOG_NEVER, "addSubdirs: Adding [%s] to search path", tmpstr );
|
||||
#endif // DEBUG
|
||||
|
@ -182,10 +182,10 @@ void removeSubdirs( const char * basedir, const char * subdir, char * checkList[
|
|||
#endif // DEBUG
|
||||
if( !checkList || inList( checkList, *i ) )
|
||||
{
|
||||
strcpy( tmpstr, basedir );
|
||||
strcat( tmpstr, subdir );
|
||||
strcat( tmpstr, PHYSFS_getDirSeparator() );
|
||||
strcat( tmpstr, *i );
|
||||
strlcpy(tmpstr, basedir, sizeof(tmpstr));
|
||||
strlcat(tmpstr, subdir, sizeof(tmpstr));
|
||||
strlcat(tmpstr, PHYSFS_getDirSeparator(), sizeof(tmpstr));
|
||||
strlcat(tmpstr, *i, sizeof(tmpstr));
|
||||
#ifdef DEBUG
|
||||
debug( LOG_NEVER, "removeSubdirs: Removing [%s] from search path", tmpstr );
|
||||
#endif // DEBUG
|
||||
|
@ -269,8 +269,8 @@ static void initialize_PhysicsFS(void)
|
|||
}
|
||||
|
||||
// Append the Warzone subdir
|
||||
strcat( tmpstr, WZ_WRITEDIR );
|
||||
strcat( tmpstr, PHYSFS_getDirSeparator() );
|
||||
strlcat(tmpstr, WZ_WRITEDIR, sizeof(tmpstr));
|
||||
strlcat(tmpstr, PHYSFS_getDirSeparator(), sizeof(tmpstr));
|
||||
|
||||
if ( !PHYSFS_setWriteDir( tmpstr ) ) {
|
||||
debug( LOG_ERROR, "Error setting write directory to \"%s\": %s",
|
||||
|
@ -303,14 +303,23 @@ static void initialize_PhysicsFS(void)
|
|||
*/
|
||||
static void scanDataDirs( void )
|
||||
{
|
||||
char tmpstr[PATH_MAX] = {'\0'}, prefix[PATH_MAX] = {'\0'};
|
||||
char tmpstr[PATH_MAX], prefix[PATH_MAX];
|
||||
char* separator;
|
||||
|
||||
// Find out which PREFIX we are in...
|
||||
strcpy( tmpstr, PHYSFS_getBaseDir() );
|
||||
*strrchr( tmpstr, *PHYSFS_getDirSeparator() ) = '\0'; // Trim ending '/', which getBaseDir always provides
|
||||
strlcpy(prefix, PHYSFS_getBaseDir(), sizeof(prefix));
|
||||
|
||||
strncpy( prefix, PHYSFS_getBaseDir(), // Skip the last dir from base dir
|
||||
strrchr( tmpstr, *PHYSFS_getDirSeparator() ) - tmpstr );
|
||||
separator = strrchr(prefix, *PHYSFS_getDirSeparator());
|
||||
if (separator)
|
||||
{
|
||||
*separator = '\0'; // Trim ending '/', which getBaseDir always provides
|
||||
|
||||
separator = strrchr(prefix, *PHYSFS_getDirSeparator());
|
||||
if (separator)
|
||||
{
|
||||
*separator = '\0'; // Skip the last dir from base dir
|
||||
}
|
||||
}
|
||||
|
||||
atexit( cleanSearchPath );
|
||||
|
||||
|
@ -325,16 +334,16 @@ static void scanDataDirs( void )
|
|||
if( !PHYSFS_exists("gamedesc.lev") )
|
||||
{
|
||||
// Data in SVN dir
|
||||
strcpy( tmpstr, prefix );
|
||||
strcat( tmpstr, "/data/" );
|
||||
strlcpy(tmpstr, prefix, sizeof(tmpstr));
|
||||
strlcat(tmpstr, "/data/", sizeof(tmpstr));
|
||||
registerSearchPath( tmpstr, 3 );
|
||||
rebuildSearchPath( mod_multiplay, TRUE );
|
||||
|
||||
if( !PHYSFS_exists("gamedesc.lev") )
|
||||
{
|
||||
// Relocation for AutoPackage
|
||||
strcpy( tmpstr, prefix );
|
||||
strcat( tmpstr, "/share/warzone2100/" );
|
||||
strlcpy(tmpstr, prefix, sizeof(tmpstr));
|
||||
strlcat(tmpstr, "/share/warzone2100/", sizeof(tmpstr));
|
||||
registerSearchPath( tmpstr, 4 );
|
||||
rebuildSearchPath( mod_multiplay, TRUE );
|
||||
|
||||
|
@ -759,8 +768,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* Put these files in the writedir root */
|
||||
setRegistryFilePath("config");
|
||||
strcpy(KeyMapPath, "keymap.map");
|
||||
strcpy(UserMusicPath, "music");
|
||||
strlcpy(KeyMapPath, "keymap.map", sizeof(KeyMapPath));
|
||||
strlcpy(UserMusicPath, "music", sizeof(UserMusicPath));
|
||||
|
||||
/*** Initialize translations ***/
|
||||
setlocale(LC_MESSAGES, "");
|
||||
|
|
|
@ -976,8 +976,7 @@ BOOL receiveWholeDroid(NETMSG *m)
|
|||
NetGet(m,sizecount,player); sizecount+=sizeof(player);
|
||||
|
||||
dt.pName = (char*)&dt.aName;
|
||||
strncpy(dt.aName, &(m->body[sizecount]), DROID_MAXNAME-1);
|
||||
dt.aName[DROID_MAXNAME-1]=0; // just in case.
|
||||
strlcpy(dt.aName, &(m->body[sizecount]), sizeof(dt.aName));
|
||||
sizecount+=strlen(dt.pName)+1; // name is pointed at directly into the buffer.
|
||||
|
||||
if(dt.asWeaps[0] == 0)
|
||||
|
|
|
@ -2366,7 +2366,7 @@ BOOL startMultiOptions(BOOL bReenter)
|
|||
game.maxPlayers = 4;
|
||||
}
|
||||
|
||||
strncpy(game.version, buildTime, 8); // note buildtime.
|
||||
strlcpy(game.version, buildTime, sizeof(game.version)); // note buildtime.
|
||||
|
||||
ingame.localOptionsReceived = FALSE;
|
||||
if(ingame.numStructureLimits)
|
||||
|
|
|
@ -471,7 +471,7 @@ void addMultiRequest(const char* searchDir, const char* fileExtension, UDWORD mo
|
|||
{
|
||||
const unsigned int tip_index = check_tip_index(sButInit.id - M_REQUEST_BUT);
|
||||
const unsigned int fileNameLength = strlen(*currFile);
|
||||
const unsigned int tipStringLength = MIN(fileNameLength - extensionLength, MAX_STR_SIZE - 1);
|
||||
const unsigned int tipStringLength = fileNameLength - extensionLength;
|
||||
|
||||
// Check to see if this file matches the given extension
|
||||
if (!(fileNameLength > extensionLength)
|
||||
|
@ -481,9 +481,7 @@ void addMultiRequest(const char* searchDir, const char* fileExtension, UDWORD mo
|
|||
// Set the tip and add the button
|
||||
|
||||
// Copy all of the filename except for the extension into the tiptext string
|
||||
strncpy(tips[tip_index], *currFile, tipStringLength);
|
||||
// Null terminate the string
|
||||
tips[count][tipStringLength] = '\0';
|
||||
strlcpy(tips[tip_index], *currFile, MIN(tipStringLength + 1, sizeof(tips[tip_index])));
|
||||
|
||||
sButInit.pTip = tips[tip_index];
|
||||
sButInit.pText = tips[tip_index];
|
||||
|
@ -506,9 +504,7 @@ void addMultiRequest(const char* searchDir, const char* fileExtension, UDWORD mo
|
|||
continue;
|
||||
|
||||
mapTextLength = tipStringLength - (mapText - *currFile);
|
||||
strncpy(tips[tip_index], mapText, mapTextLength);
|
||||
// Null terminate the string
|
||||
tips[tip_index][mapTextLength] = '\0';
|
||||
strlcpy(tips[tip_index], mapText, MIN(mapTextLength + 1, sizeof(tips[tip_index])));
|
||||
}
|
||||
|
||||
++count;
|
||||
|
|
|
@ -438,8 +438,7 @@ BOOL addTemplate(UDWORD player, DROID_TEMPLATE *psNew)
|
|||
memcpy(psTempl, psNew, sizeof(DROID_TEMPLATE));
|
||||
|
||||
psTempl->pName = (char*)&psTempl->aName;
|
||||
strncpy(psTempl->aName, psNew->aName,DROID_MAXNAME);
|
||||
psTempl->pName[DROID_MAXNAME-1]=0;
|
||||
strlcpy(psTempl->aName, psNew->aName, sizeof(psTempl->aName));
|
||||
|
||||
|
||||
psTempl->psNext = apsDroidTemplates[player];
|
||||
|
|
|
@ -1198,10 +1198,10 @@ BOOL recvTextMessage(NETMSG *pMsg)
|
|||
ASSERT(player != MAX_PLAYERS, "recvTextMessage: failed to find owner of dpid %d", dpid);
|
||||
|
||||
//sprintf(msg, "%d", i);
|
||||
strcpy(msg,NetPlay.players[i].name);
|
||||
strcat(msg," : "); // seperator
|
||||
//strcat(msg, &(pMsg->body[4])); // add message
|
||||
strncat(msg, &(pMsg->body[4]), sizeof(msg) - strlen(msg) - 1); // add message
|
||||
strlcpy(msg, NetPlay.players[i].name, sizeof(msg));
|
||||
strlcat(msg, " : ", sizeof(msg)); // seperator
|
||||
//strlcat(msg, &(pMsg->body[4]), sizeof(msg)); // add message
|
||||
strlcat(msg, &(pMsg->body[4]), sizeof(msg)); // add message
|
||||
addConsoleMessage((char *)&msg,DEFAULT_JUSTIFY);
|
||||
|
||||
//multiplayer message callback
|
||||
|
@ -1210,7 +1210,7 @@ BOOL recvTextMessage(NETMSG *pMsg)
|
|||
MultiMsgPlayerFrom = player;
|
||||
MultiMsgPlayerTo = selectedPlayer;
|
||||
|
||||
strcpy(MultiplayMsg,&(pMsg->body[4]));
|
||||
strlcpy(MultiplayMsg, &(pMsg->body[4]), sizeof(MultiplayMsg));
|
||||
eventFireCallbackTrigger((TRIGGER_TYPE)CALL_AI_MSG);
|
||||
|
||||
// make some noise!
|
||||
|
@ -1236,9 +1236,9 @@ BOOL recvTextMessageAI(NETMSG *pMsg)
|
|||
NetGet(pMsg,0,sender); //in-game player index ('normal' one)
|
||||
NetGet(pMsg,4,receiver); //in-game player index
|
||||
|
||||
//strcpy(msg,getPlayerName(sender)); // name
|
||||
//strcat(msg," : "); // seperator
|
||||
strcpy(msg, &(pMsg->body[8]));
|
||||
//strlcpy(msg, getPlayerName(sender), sizeof(msg)); // name
|
||||
//strlcat(msg, " : ", sizeof(msg)); // seperator
|
||||
strlcpy(msg, &(pMsg->body[8]), sizeof(msg));
|
||||
|
||||
//Display the message and make the script callback
|
||||
displayAIMessage(msg, sender, receiver);
|
||||
|
@ -1550,21 +1550,20 @@ BOOL recvMapFileRequested(NETMSG *pMsg)
|
|||
addConsoleMessage("SENDING MAP!",DEFAULT_JUSTIFY);
|
||||
addConsoleMessage("FIX FOR LINUX!",DEFAULT_JUSTIFY);
|
||||
|
||||
strcpy(mapName,game.map);
|
||||
strlcpy(mapName, game.map, sizeof(mapName));
|
||||
// chop off the -T1
|
||||
mapName[strlen(game.map)-3] = 0; // chop off the -T1 etc..
|
||||
|
||||
// chop off the sk- if required.
|
||||
if(strncmp(mapName,"Sk-",3) == 0)
|
||||
{
|
||||
strcpy(mapStr,&(mapName[3]));
|
||||
strcpy(mapName,mapStr);
|
||||
strlcpy(mapStr, &(mapName[3]), sizeof(mapStr));
|
||||
strlcpy(mapName, mapStr, sizeof(mapName));
|
||||
}
|
||||
|
||||
sprintf(mapStr,"%dc-%s",game.maxPlayers,mapName);
|
||||
strcat(mapStr,".wz");//.wdg
|
||||
sprintf(fixedname,"maps/%s",mapStr); //We know maps are in /maps dir...now. fix for linux -Q
|
||||
memcpy(mapStr,fixedname,256);
|
||||
snprintf(mapStr, sizeof(mapStr), "%dc-%s.wz", game.maxPlayers, mapName);
|
||||
snprintf(fixedname, sizeof(fixedname), "maps/%s", mapStr); //We know maps are in /maps dir...now. fix for linux -Q
|
||||
strlcpy(mapStr, fixedname, sizeof(mapStr));
|
||||
NETsendFile(TRUE,mapStr,0);
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ static int newPage(const char *name, int level, int width, int height, int count
|
|||
ASSERT(_TEX_INDEX > texPage, "newPage: Index too low (%d > %d)", _TEX_INDEX, texPage);
|
||||
ASSERT(_TEX_INDEX < iV_TEX_MAX, "Too many texture pages used");
|
||||
|
||||
strncpy(_TEX_PAGE[texPage].name, name, iV_TEXNAME_MAX);
|
||||
strlcpy(_TEX_PAGE[texPage].name, name, sizeof(_TEX_PAGE[texPage].name));
|
||||
|
||||
pie_SetTexturePage(texPage);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
|
||||
|
|
Loading…
Reference in New Issue