diff --git a/src/deh_soc.c b/src/deh_soc.c index 4fb40b087..853c7f182 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -3213,12 +3213,12 @@ void readfollower(MYFILE *f) if (fastcmp(word, "NAME")) { - strcpy(followers[numfollowers].name, word2); + strlcpy(followers[numfollowers].name, word2, SKINNAMESIZE+1); nameset = true; } else if (fastcmp(word, "ICON")) { - strcpy(followers[numfollowers].icon, word2); + strlcpy(followers[numfollowers].icon, word2, 8+1); nameset = true; } else if (fastcmp(word, "CATEGORY")) @@ -3362,30 +3362,26 @@ void readfollower(MYFILE *f) if (!nameset) { // well this is problematic. - strcpy(followers[numfollowers].name, va("Follower%d", numfollowers)); // this is lazy, so what + strlcpy(followers[numfollowers].name, va("Follower%d", numfollowers), SKINNAMESIZE+1); + strcpy(testname, followers[numfollowers].name); } - - // set skin name (this is just the follower's name in lowercases): - // but before we do, let's... actually check if another follower isn't doing the same shit... - - res = K_FollowerAvailable(testname); - if (res > -1) // yikes, someone else has stolen our name already + else { - INT32 startlen = strlen(testname); - char cpy[2]; - //deh_warning("There was already a follower with the same name. (%s)", testname); This warning probably isn't necessary anymore? - sprintf(cpy, "%d", numfollowers); - memcpy(&testname[startlen], cpy, 2); - // in that case, we'll be very lazy and copy numfollowers to the end of our skin name. - } + strcpy(testname, followers[numfollowers].name); - strcpy(testname, followers[numfollowers].name); + // now that the skin name is ready, post process the actual name to turn the underscores into spaces! + for (i = 0; followers[numfollowers].name[i]; i++) + { + if (followers[numfollowers].name[i] == '_') + followers[numfollowers].name[i] = ' '; + } - // now that the skin name is ready, post process the actual name to turn the underscores into spaces! - for (i = 0; followers[numfollowers].name[i]; i++) - { - if (followers[numfollowers].name[i] == '_') - followers[numfollowers].name[i] = ' '; + res = K_FollowerAvailable(followers[numfollowers].name); + if (res > -1) // yikes, someone else has stolen our name already + { + deh_warning("Follower%d: Name \"%s\" already in use!", numfollowers, testname); + strlcpy(followers[numfollowers].name, va("Follower%d", numfollowers), SKINNAMESIZE+1); + } } // fallbacks for variables diff --git a/src/filesrch.c b/src/filesrch.c index 6f18cdd83..1d01a44fc 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -172,6 +172,7 @@ opendir (const CHAR *szPath) /* Initialize the dirent structure. ino and reclen are invalid under * Win32, and name simply points at the appropriate part of the * findfirst_t structure. */ + nd->dd_dta = (struct _finddata_t) {0}; nd->dd_dir.d_ino = 0; nd->dd_dir.d_reclen = 0; nd->dd_dir.d_namlen = 0; @@ -450,7 +451,7 @@ filestatus_t filesearch(char *filename, const char *startpath, const UINT8 *want filestatus_t retval = FS_NOTFOUND; DIR **dirhandle; struct dirent *dent; - struct stat fsstat; + struct stat fsstat = {0}; int found = 0; char *searchname = strdup(filename); int depthleft = maxsearchdepth; @@ -709,7 +710,7 @@ boolean preparefilemenu(boolean samedepth, boolean replayhut) { DIR *dirhandle; struct dirent *dent; - struct stat fsstat; + struct stat fsstat = {0}; size_t pos = 0, folderpos = 0, numfolders = 0; char *tempname = NULL; diff --git a/src/k_brightmap.c b/src/k_brightmap.c index a70d7a955..5b9963426 100644 --- a/src/k_brightmap.c +++ b/src/k_brightmap.c @@ -86,7 +86,7 @@ static brightmapStorage_t *K_GetBrightmapStorageByTextureName(const char *checkN } /*-------------------------------------------------- - static boolean K_BRIGHTLumpParser(UINT8 *data, size_t size) + static boolean K_BRIGHTLumpParser(char *data, size_t size) Parses inputted lump data as a BRIGHT lump. @@ -97,7 +97,7 @@ static brightmapStorage_t *K_GetBrightmapStorageByTextureName(const char *checkN Return:- false if any errors occured, otherwise true. --------------------------------------------------*/ -static boolean K_BRIGHTLumpParser(UINT8 *data, size_t size) +static boolean K_BRIGHTLumpParser(char *data, size_t size) { char *tkn = M_GetToken((char *)data); size_t pos = 0; @@ -188,6 +188,7 @@ void K_InitBrightmapsPwad(INT32 wadNum) { lumpinfo_t *lump_p = &wadfiles[wadNum]->lumpinfo[lumpNum]; size_t size = W_LumpLengthPwad(wadNum, lumpNum); + char *datacopy; size_t nameLength = strlen(wadfiles[wadNum]->filename) + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name char *name = malloc(nameLength + 1); @@ -198,10 +199,18 @@ void K_InitBrightmapsPwad(INT32 wadNum) size = W_LumpLengthPwad(wadNum, lumpNum); CONS_Printf(M_GetText("Loading BRIGHT from %s\n"), name); - K_BRIGHTLumpParser(data, size); + + datacopy = (char *)Z_Malloc((size+1)*sizeof(char),PU_STATIC,NULL); + memmove(datacopy,data,size); + datacopy[size] = '\0'; + + Z_Free(data); + + K_BRIGHTLumpParser(datacopy, size); + + Z_Free(datacopy); free(name); - Z_Free(data); } lumpNum = W_CheckNumForNamePwad("BRIGHT", (UINT16)wadNum, lumpNum + 1); diff --git a/src/k_terrain.c b/src/k_terrain.c index a702f53ad..322aecdce 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -1734,7 +1734,7 @@ static boolean K_DoTERRAINLumpParse(size_t num, void (*parser)(size_t, char *, c } /*-------------------------------------------------- - static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) + static boolean K_TERRAINLumpParser(char *data, size_t size) Parses inputted lump data as a TERRAIN lump. @@ -1745,9 +1745,9 @@ static boolean K_DoTERRAINLumpParse(size_t num, void (*parser)(size_t, char *, c Return:- false if any errors occured, otherwise true. --------------------------------------------------*/ -static boolean K_TERRAINLumpParser(UINT8 *data, size_t size) +static boolean K_TERRAINLumpParser(char *data, size_t size) { - char *tkn = M_GetToken((char *)data); + char *tkn = M_GetToken(data); UINT32 tknHash = 0; size_t pos = 0; size_t i; @@ -2136,6 +2136,7 @@ void K_InitTerrain(UINT16 wadNum) else { size_t size = W_LumpLengthPwad(wadNum, lumpNum); + char *datacopy; size_t nameLength = strlen(wadfiles[wadNum]->filename) + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name char *name = malloc(nameLength + 1); @@ -2146,7 +2147,16 @@ void K_InitTerrain(UINT16 wadNum) size = W_LumpLengthPwad(wadNum, lumpNum); CONS_Printf(M_GetText("Loading TERRAIN from %s\n"), name); - K_TERRAINLumpParser(data, size); + + datacopy = (char *)Z_Malloc((size+1)*sizeof(char),PU_STATIC,NULL); + memmove(datacopy,data,size); + datacopy[size] = '\0'; + + Z_Free(data); + + K_TERRAINLumpParser(datacopy, size); + + Z_Free(datacopy); free(name); } diff --git a/src/m_misc.c b/src/m_misc.c index cf03c5e2d..25a6c8624 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1940,14 +1940,14 @@ char *M_GetToken(const char *inputString) } // Find the first non-whitespace char, or else the end of the string trying - while ((stringToUse[startPos] == ' ' + while (startPos < stringLength + && (stringToUse[startPos] == ' ' || stringToUse[startPos] == '\t' || stringToUse[startPos] == '\r' || stringToUse[startPos] == '\n' || stringToUse[startPos] == '\0' || stringToUse[startPos] == '=' || stringToUse[startPos] == ';' // UDMF TEXTMAP. - || inComment != 0) - && startPos < stringLength) + || inComment != 0)) { // Try to detect comment endings now if (inComment == 1 @@ -1988,7 +1988,7 @@ char *M_GetToken(const char *inputString) } // If the end of the string is reached, no token is to be read - if (startPos == stringLength) { + if (startPos >= stringLength) { endPos = stringLength; return NULL; } @@ -2007,7 +2007,7 @@ char *M_GetToken(const char *inputString) else if (stringToUse[startPos] == '"') { endPos = ++startPos; - while (stringToUse[endPos] != '"' && endPos < stringLength) + while (endPos < stringLength && stringToUse[endPos] != '"') endPos++; texturesTokenLength = endPos++ - startPos; @@ -2023,7 +2023,8 @@ char *M_GetToken(const char *inputString) // Now find the end of the token. This includes several additional characters that are okay to capture as one character, but not trailing at the end of another token. endPos = startPos + 1; - while ((stringToUse[endPos] != ' ' + while (endPos < stringLength + && (stringToUse[endPos] != ' ' && stringToUse[endPos] != '\t' && stringToUse[endPos] != '\r' && stringToUse[endPos] != '\n' @@ -2031,8 +2032,7 @@ char *M_GetToken(const char *inputString) && stringToUse[endPos] != '{' && stringToUse[endPos] != '}' && stringToUse[endPos] != '=' && stringToUse[endPos] != ';' // UDMF TEXTMAP. - && inComment == 0) - && endPos < stringLength) + && inComment == 0)) { endPos++; // Try to detect comment starts now; if it's in a comment, we don't want it in this token diff --git a/src/s_sound.c b/src/s_sound.c index 1fc80cf8e..0d3746d33 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -268,8 +268,6 @@ void S_RegisterSoundStuff(void) static void SetChannelsNum(void) { - INT32 i; - // Allocating the internal channels for mixing // (the maximum number of sounds rendered // simultaneously) within zone memory. @@ -291,12 +289,8 @@ static void SetChannelsNum(void) } #endif if (cv_numChannels.value) - channels = (channel_t *)Z_Malloc(cv_numChannels.value * sizeof (channel_t), PU_STATIC, NULL); - numofchannels = cv_numChannels.value; - - // Free all channels for use - for (i = 0; i < numofchannels; i++) - channels[i].sfxinfo = 0; + channels = (channel_t *)Z_Calloc(cv_numChannels.value * sizeof (channel_t), PU_STATIC, NULL); + numofchannels = (channels ? cv_numChannels.value : 0); S_ResetCaptions(); } diff --git a/src/v_video.c b/src/v_video.c index e633b4e3f..9f707ef1c 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -476,6 +476,8 @@ void V_SetPaletteLump(const char *pal) static void CV_palette_OnChange(void) { + if (con_startup_loadprogress < LOADED_CONFIG) + return; // recalculate Color Cube V_ReloadPalette(); V_SetPalette(0);