[vlc-devel] [PATCH 1/2] directory: Don't append a separator when it's not needed

Hugo Beauzée-Luyssen hugo at beauzee.fr
Fri Feb 21 12:09:20 CET 2020


---
 modules/access/directory.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/modules/access/directory.c b/modules/access/directory.c
index 8fa3c0a5e3..72182bd734 100644
--- a/modules/access/directory.c
+++ b/modules/access/directory.c
@@ -44,6 +44,7 @@
 typedef struct
 {
     char *base_uri;
+    bool need_separator;
     DIR *dir;
 } access_sys_t;
 
@@ -67,6 +68,12 @@ int DirInit (stream_t *access, DIR *dir)
     if (unlikely(sys->base_uri == NULL))
         goto error;
 
+    char last_char = sys->base_uri[strlen(sys->base_uri) - 1];
+    sys->need_separator =
+#ifdef _WIN32
+            last_char != '\\' &&
+#endif
+            last_char != '/';
     sys->dir = dir;
 
     access->p_sys = sys;
@@ -174,7 +181,9 @@ int DirRead (stream_t *access, input_item_node_t *node)
         }
 
         char *uri;
-        if (unlikely(asprintf(&uri, "%s/%s", sys->base_uri, encoded) == -1))
+        if (unlikely(asprintf(&uri, "%s%s%s", sys->base_uri,
+                              sys->need_separator ? "/" : "",
+                              encoded) == -1))
             uri = NULL;
         free(encoded);
         if (unlikely(uri == NULL))
-- 
2.20.1



More information about the vlc-devel mailing list