shithub: choc

Download patch

ref: bec0d85ca98d682c3d922d76309976a3a1359e3c
parent: 2435843ccd797d6bd70fa41872b92657cf6e98dc
author: Turo Lamminen <turol@users.noreply.github.com>
date: Sat Mar 12 09:03:24 EST 2022

Gracefully handle SDL_GetPrefPath returning NULL (#1450)

* music: Warn if SDL_GetPrefPath fails and music pack directory can't be set

* doom: Handle M_GetAutoloadDir returning NULL

* heretic: Handle M_GetAutoloadDir returning NULL

* hexen: Handle M_GetAutoloadDir returning NULL

* strife: Handle M_GetAutoloadDir returning NULL

* Avoid crash in M_GetAutoloadDir if SDL_GetPrefPath fails

--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -1605,16 +1605,22 @@
         if (gamemission < pack_chex)
         {
             autoload_dir = M_GetAutoloadDir("doom-all");
-            DEH_AutoLoadPatches(autoload_dir);
-            W_AutoLoadWADs(autoload_dir);
-            free(autoload_dir);
+            if (autoload_dir != NULL)
+            {
+                DEH_AutoLoadPatches(autoload_dir);
+                W_AutoLoadWADs(autoload_dir);
+                free(autoload_dir);
+            }
         }
 
         // auto-loaded files per IWAD
         autoload_dir = M_GetAutoloadDir(D_SaveGameIWADName(gamemission, gamevariant));
-        DEH_AutoLoadPatches(autoload_dir);
-        W_AutoLoadWADs(autoload_dir);
-        free(autoload_dir);
+        if (autoload_dir != NULL)
+        {
+            DEH_AutoLoadPatches(autoload_dir);
+            W_AutoLoadWADs(autoload_dir);
+            free(autoload_dir);
+        }
     }
 
     // Load Dehacked patches specified on the command line with -deh.
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -909,9 +909,12 @@
     {
         char *autoload_dir;
         autoload_dir = M_GetAutoloadDir("heretic.wad");
-        DEH_AutoLoadPatches(autoload_dir);
-        W_AutoLoadWADs(autoload_dir);
-        free(autoload_dir);
+        if (autoload_dir != NULL)
+        {
+            DEH_AutoLoadPatches(autoload_dir);
+            W_AutoLoadWADs(autoload_dir);
+            free(autoload_dir);
+        }
     }
 
     // Load dehacked patches specified on the command line.
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -448,9 +448,12 @@
     {
         char *autoload_dir;
         autoload_dir = M_GetAutoloadDir("hexen.wad");
-        // TODO? DEH_AutoLoadPatches(autoload_dir);
-        W_AutoLoadWADs(autoload_dir);
-        free(autoload_dir);
+        if (autoload_dir != NULL)
+        {
+            // TODO? DEH_AutoLoadPatches(autoload_dir);
+            W_AutoLoadWADs(autoload_dir);
+            free(autoload_dir);
+        }
     }
 
     HandleArgs();
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -2406,6 +2406,11 @@
     }
 
     prefdir = SDL_GetPrefPath("", PACKAGE_TARNAME);
+    if (prefdir == NULL)
+    {
+        printf("M_SetMusicPackDir: SDL_GetPrefPath failed, music pack directory not set\n");
+        return;
+    }
     music_pack_path = M_StringJoin(prefdir, "music-packs", NULL);
 
     M_MakeDirectory(prefdir);
@@ -2502,6 +2507,11 @@
     {
         char *prefdir;
         prefdir = SDL_GetPrefPath("", PACKAGE_TARNAME);
+        if (prefdir == NULL)
+        {
+            printf("M_GetAutoloadDir: SDL_GetPrefPath failed\n");
+            return NULL;
+        }
         autoload_path = M_StringJoin(prefdir, "autoload", NULL);
         SDL_free(prefdir);
     }
--- a/src/strife/d_main.c
+++ b/src/strife/d_main.c
@@ -1761,9 +1761,12 @@
     {
         char *autoload_dir;
         autoload_dir = M_GetAutoloadDir("strife1.wad");
-        DEH_AutoLoadPatches(autoload_dir);
-        W_AutoLoadWADs(autoload_dir);
-        free(autoload_dir);
+        if (autoload_dir != NULL)
+        {
+            DEH_AutoLoadPatches(autoload_dir);
+            W_AutoLoadWADs(autoload_dir);
+            free(autoload_dir);
+        }
     }
 
     // Load dehacked patches specified on the command line.