shithub: choc

Download patch

ref: 4ae3076411ebed9439a9eee3ec75d92a1b230813
parent: b98b4e6be6ec33ddeb27cf0a919b2a0b8664a0d9
author: Simon Howard <fraggle@soulsphere.org>
date: Sun Oct 28 15:05:52 EDT 2018

Use M_StringJoin() instead of hand-rolled malloc.

--- a/src/d_iwad.c
+++ b/src/d_iwad.c
@@ -385,8 +385,7 @@
 {
     const char *current_path;
     char *install_path;
-    char *patch_path;
-    int len;
+    char *test_patch_path, patch_path;
 
     // Already configured? Don't stomp on the user's choices.
     current_path = M_GetStringVariable("gus_patch_path");
@@ -402,19 +401,17 @@
         return;
     }
 
-    len = strlen(install_path) + strlen(STEAM_BFG_GUS_PATCHES) + 20;
-    patch_path = malloc(len);
-    M_snprintf(patch_path, len, "%s\\%s\\ACBASS.PAT",
-               install_path, STEAM_BFG_GUS_PATCHES);
+    patch_path = M_StringJoin(install_path, "\\", STEAM_BFG_GUS_PATCHES,
+                              NULL);
+    test_patch_path = M_StringJoin(patch_path, "\\ACBASS.PAT", NULL);
 
     // Does acbass.pat exist? If so, then set gus_patch_path.
-    if (M_FileExists(patch_path))
+    if (M_FileExists(test_patch_path))
     {
-        M_snprintf(patch_path, len, "%s\\%s",
-                   install_path, STEAM_BFG_GUS_PATCHES);
         M_SetVariable("gus_patch_path", patch_path);
     }
 
+    free(test_patch_path);
     free(patch_path);
     free(install_path);
 }