From: Holger Schemel Date: Fri, 24 Aug 2018 10:31:53 +0000 (+0200) Subject: changed filename string handling for level file info structure X-Git-Tag: 4.1.1.0~59 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=759e0bea3ad909b5be8757aa7c2409fc1c52f493;p=rocksndiamonds.git changed filename string handling for level file info structure Before, level filenames in the level file info structure (members for "basename" and "filename") were only handled as references to the basename/filename strings allocated elsewhere, so if those strings changed, the references in the level file info structure also pointed to those changed strings. When determining filenames for both level files and corresponding level templates, references to level filenames were replaced by references to template filenames, which resulted in unexpected/wrong behaviour. Now, these level filenames are handled as copies of the strings, so if the strings change, the string copies still stay the same. --- diff --git a/src/files.c b/src/files.c index 3cb8fc72..b590641a 100644 --- a/src/files.c +++ b/src/files.c @@ -1855,8 +1855,9 @@ static void setFileInfoToDefaults(struct LevelFileInfo *level_file_info) level_file_info->nr = 0; level_file_info->type = LEVEL_FILE_TYPE_UNKNOWN; level_file_info->packed = FALSE; - level_file_info->basename = NULL; - level_file_info->filename = NULL; + + setString(&level_file_info->basename, NULL); + setString(&level_file_info->filename, NULL); } int getMappedElement_SB(int, boolean); @@ -2088,8 +2089,9 @@ static void setLevelFileInfo_SingleLevelFilename(struct LevelFileInfo *lfi, { lfi->type = type; lfi->packed = FALSE; - lfi->basename = getSingleLevelBasename(lfi->nr, lfi->type); - lfi->filename = getLevelFilenameFromBasename(lfi->basename); + + setString(&lfi->basename, getSingleLevelBasename(lfi->nr, lfi->type)); + setString(&lfi->filename, getLevelFilenameFromBasename(lfi->basename)); } #endif @@ -2105,8 +2107,9 @@ static void setLevelFileInfo_FormatLevelFilename(struct LevelFileInfo *lfi, lfi->type = type; lfi->packed = FALSE; - lfi->basename = basename; - lfi->filename = getLevelFilenameFromBasename(lfi->basename); + + setString(&lfi->basename, basename); + setString(&lfi->filename, getLevelFilenameFromBasename(lfi->basename)); } static void setLevelFileInfo_PackedLevelFilename(struct LevelFileInfo *lfi, @@ -2114,8 +2117,9 @@ static void setLevelFileInfo_PackedLevelFilename(struct LevelFileInfo *lfi, { lfi->type = type; lfi->packed = TRUE; - lfi->basename = getPackedLevelBasename(lfi->type); - lfi->filename = getLevelFilenameFromBasename(lfi->basename); + + setString(&lfi->basename, getPackedLevelBasename(lfi->type)); + setString(&lfi->filename, getLevelFilenameFromBasename(lfi->basename)); } static int getFiletypeFromID(char *filetype_id) @@ -2187,7 +2191,7 @@ static void determineLevelFileInfo_Filename(struct LevelFileInfo *lfi) getSingleLevelBasename(-1)); /* replace local level template filename with global template filename */ - lfi->filename = getGlobalLevelTemplateFilename(); + setString(&lfi->filename, getGlobalLevelTemplateFilename()); /* no fallback if template file not existing */ return; @@ -6201,7 +6205,8 @@ void LoadLevelFromFilename(struct LevelInfo *level, char *filename) level_file_info.nr = 0; /* unknown level number */ level_file_info.type = LEVEL_FILE_TYPE_RND; /* no others supported yet */ - level_file_info.filename = filename; + + setString(&level_file_info.filename, filename); LoadLevelFromFileInfo(level, &level_file_info, FALSE); }