From 70e751e46a96fe09543047f5c4cb8884de3d5b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Tue, 20 Apr 2021 03:26:05 +0300 Subject: [PATCH] =?UTF-8?q?Don't=20collapse=20//=20=E2=86=92=20/=20in=20co?= =?UTF-8?q?mpress=5Fpath(),=20and=20avoid=20generating=20//=20in=20the=20f?= =?UTF-8?q?irst=20place?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/dir.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/common/dir.c b/common/dir.c index 34b0cb9..ad9d71b 100644 --- a/common/dir.c +++ b/common/dir.c @@ -62,6 +62,7 @@ char *p; * compress_path * * This assumes sizeof(char) == 1 which is probably a really bad idea. + * ^ actually that's guaranteed by C standard -nortti, 2021 */ char * compress_path(mp, c, cwd) @@ -78,7 +79,10 @@ char *cwd; if (*cwd != '/') return(NULL); r = (char *)MPGet(mp, strlen("/") + strlen(c) + strlen(cwd) + 1); strcpy(r, cwd); - strcat(r, "/"); + // Only add the slash if we don't already have one + // That is, if cwd ends in a slash, don't add an extra one + if (r[strlen(cwd) - 1] != '/') + strcat(r, "/"); strcat(r, c); } else r = MPStrDup(mp, c); @@ -88,12 +92,7 @@ char *cwd; if (*p == '/') { p1 = p + 1; - if (*p1 == '/') - { - memmove(p, p1, strlen(p1) + 1); - continue; - } - else if (*p1 == '.') + if (*p1 == '.') { p2 = p1 + 1; if (*p2 == '/')