diff --git a/src/misc1.c b/src/misc1.c
index b0f7e91fcccfdb0c9c1266877b7556134cbe9233..6f197f22bfd39b29c43b5964f66fff7f7b227f8b 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -9593,6 +9593,8 @@ expand_in_path(gap, pattern, flags)
 
     expand_path_option(curdir, &path_ga);
     vim_free(curdir);
+    if (path_ga.ga_len == 0)
+	return 0;
     path_list = (char_u **)(path_ga.ga_data);
 # ifdef WIN3264
     if ((file_pattern = alloc((unsigned)MAXPATHL)) == NULL)