commit 261070e48f5f1c022d1fcd7d1c7df3d474231eb8
parent 8e595a498d1835ac8515200142477251c2dd4e89
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Sat, 19 Dec 2020 23:36:23 -0800
Fix new path generation
newpath()'s `path` was uninitialized.
Diffstat:
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/main.c b/main.c
@@ -147,18 +147,17 @@ strtoui(const char *s)
return i;
}
+/* `path` old path, `newpath` new path. Result put into `path`. */
void
-newpath(char *path, char *newpath)
+newpath(char *path, const char *newpath)
{
- size_t len;
+ char tmp[PATH_MAX];
if (*newpath == '/') {
strlcpy(path, newpath, PATH_MAX);
} else {
- len = strlen(path);
- if (len > 0 && path[len - 1] != '/')
- path[len - 1] = '/';
- strncat(path, newpath, PATH_MAX);
+ snprintf(tmp, PATH_MAX, "%s/%s", path, newpath);
+ strlcpy(path, tmp, PATH_MAX);
}
}
@@ -333,9 +332,10 @@ cgoto(int argc, char **argv, int depth, const char *tmpdir, const char *host, co
nhost = host;
nport = port;
+ strcpy(npath, path);
if (argc == 0)
- strcpy(npath, "/");
+ newpath(npath, "/");
else if (argc == 1)
newpath(npath, argv[0]);
else {