Fix path handling in _gsound_get_music_path

This commit is contained in:
Alexander Batalov 2022-10-08 10:56:46 +03:00
parent a4105d5826
commit 4c1020af5f
1 changed files with 13 additions and 11 deletions

View File

@ -1951,35 +1951,37 @@ int speechPlay()
return 0; return 0;
} }
// TODO: Refactor to use Settings.
//
// 0x452208 // 0x452208
int _gsound_get_music_path(char** out_value, const char* key) int _gsound_get_music_path(char** out_value, const char* key)
{ {
size_t v3; size_t len;
char* v4; char* copy;
char* value; char* value;
configGetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, key, out_value); configGetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, key, out_value);
value = *out_value; value = *out_value;
v3 = strlen(value) + 1; len = strlen(value);
if (*(value + v3 - 2) == '\\') { if (value[len - 1] == '\\' || value[len - 1] == '/') {
return 0; return 0;
} }
v4 = (char*)internal_malloc(v3 - 1 + 2); copy = (char*)internal_malloc(len + 2);
if (v4 == NULL) { if (copy == NULL) {
if (gGameSoundDebugEnabled) { if (gGameSoundDebugEnabled) {
debugPrint("Out of memory in gsound_get_music_path.\n"); debugPrint("Out of memory in gsound_get_music_path.\n");
} }
return -1; return -1;
} }
strcpy(v4, value); strcpy(copy, value);
*(v4 + v3) = '\\'; copy[len] = '\\';
*(v4 + v3 + 1) = '\0'; copy[len + 1] = '\0';
if (configSetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, key, v4) != 1) { if (configSetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, key, copy) != 1) {
if (gGameSoundDebugEnabled) { if (gGameSoundDebugEnabled) {
debugPrint("config_set_string failed in gsound_music_path.\n"); debugPrint("config_set_string failed in gsound_music_path.\n");
} }
@ -1988,7 +1990,7 @@ int _gsound_get_music_path(char** out_value, const char* key)
} }
if (configGetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, key, out_value)) { if (configGetString(&gGameConfig, GAME_CONFIG_SOUND_KEY, key, out_value)) {
internal_free(v4); internal_free(copy);
return 0; return 0;
} }