From 7c800f663183f53a4439640f3b6d995659e5b1ea Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Sun, 25 Jan 2015 12:18:11 +0000 Subject: [PATCH] Don't allow Ogg Vorbis or FLAC files to be defined from def if the binary was built without the proper libraries. git-svn-id: https://svn.eduke32.com/eduke32@4949 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 711012fed..359cc6384 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -9255,16 +9255,29 @@ static void G_ShowDebugHelp(void) #endif } +static int32_t S_DefineAudioIfSupported(char **fn, const char *name) +{ +#if !defined HAVE_FLAC || !defined HAVE_VORBIS + const char *extension = Bstrrchr(name, '.'); +# if !defined HAVE_FLAC + if (!Bstrcasecmp(extension, ".flac")) + return -2; +# endif +# if !defined HAVE_VORBIS + if (!Bstrcasecmp(extension, ".ogg")) + return -2; +# endif +#endif + realloc_copy(fn, name); + return 0; +} + static int32_t S_DefineSound(int32_t ID, const char *name) { if ((unsigned)ID >= MAXSOUNDS) - return 1; + return -1; - realloc_copy(&g_sounds[ID].filename, name); - -// S_LoadSound(ID); - - return 0; + return S_DefineAudioIfSupported(&g_sounds[ID].filename, name); } // Returns: @@ -9295,9 +9308,7 @@ static int32_t S_DefineMusic(const char *ID, const char *name) return -1; } - realloc_copy(&MapInfo[sel].musicfn, name); - - return 0; + return S_DefineAudioIfSupported(&MapInfo[sel].musicfn, name); } static int32_t parsedefinitions_game(scriptfile *script, int32_t preload); @@ -9612,7 +9623,7 @@ static int32_t parsedefinitions_game(scriptfile *script, int32_t preload) if (check_file_exist(fn)) break; - if (S_DefineSound(num,fn)) + if (S_DefineSound(num,fn) == -1) initprintf("Error: invalid sound ID on line %s:%d\n", script->filename, scriptfile_getlinum(script,tinttokptr)); } }