diff --git a/src/m_misc.c b/src/m_misc.c
index 5f75aae925f56f5874d842974c0f273c2c5bc424..83c0c7bec261b9ece8fbaa65c5d9c6d48fbe8b2d 100644
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -2457,6 +2457,8 @@ int M_PathParts(const char *path)
 	int n;
 	const char *p;
 	const char *t;
+	if (path == NULL)
+		return 0;
 	for (n = 0, p = path ;; ++n)
 	{
 		t = p;
diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c
index 8a4fa06b5de73ce0bf4754bcca8a71c2f7fecb41..5d0009927f1f64579c538d2cc604ee30fa3aa007 100644
--- a/src/sdl/i_main.c
+++ b/src/sdl/i_main.c
@@ -197,12 +197,9 @@ int main(int argc, char **argv)
 					format, timeinfo);
 		}
 
-		if (logdir)
-		{
-			M_MkdirEachUntil(logfilename,
-					M_PathParts(logdir) - 1,
-					M_PathParts(logfilename) - 1, 0755);
-		}
+		M_MkdirEachUntil(logfilename,
+				M_PathParts(logdir) - 1,
+				M_PathParts(logfilename) - 1, 0755);
 
 #ifdef __unix__
 		logstream = fopen(logfilename, "w");