fix joinpath(): use of global 'repodir', should be 'path' - stagit-gopher - A git gopher frontend. (mirror) HTML git clone git://bitreich.org/stagit-gopher/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/stagit-gopher/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit 543582034eed3faf6120de321354f36ec8a2c0b4 DIR parent 2d8eb85f01fdb97ab76c538b868128db4c3e99f0 HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Tue, 3 May 2016 20:42:46 +0200 fix joinpath(): use of global 'repodir', should be 'path' use joinpath for another case. Diffstat: M stagit-index.c | 24 ++++++++++++------------ M stagit.c | 39 ++++++++++++++----------------- 2 files changed, 29 insertions(+), 34 deletions(-) --- DIR diff --git a/stagit-index.c b/stagit-index.c @@ -30,6 +30,18 @@ pledge(const char *promises, const char *paths[]) } #endif +void +joinpath(char *buf, size_t bufsiz, const char *path, const char *path2) +{ + int r; + + r = snprintf(buf, bufsiz, "%s%s%s", + path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2); + if (r == -1 || (size_t)r >= bufsiz) + errx(1, "path truncated: '%s%s%s'", + path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2); +} + /* Escape characters below as HTML 2.0 / XML 1.0. */ void xmlencode(FILE *fp, const char *s, size_t len) @@ -139,18 +151,6 @@ err: return ret; } -void -joinpath(char *buf, size_t bufsiz, const char *path, const char *path2) -{ - int r; - - r = snprintf(buf, bufsiz, "%s%s%s", - repodir, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2); - if (r == -1 || (size_t)r >= bufsiz) - errx(1, "path truncated: '%s%s%s'", - path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2); -} - int main(int argc, char *argv[]) { DIR diff --git a/stagit.c b/stagit.c @@ -77,6 +77,18 @@ pledge(const char *promises, const char *paths[]) #endif void +joinpath(char *buf, size_t bufsiz, const char *path, const char *path2) +{ + int r; + + r = snprintf(buf, bufsiz, "%s%s%s", + path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2); + if (r == -1 || (size_t)r >= bufsiz) + errx(1, "path truncated: '%s%s%s'", + path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2); +} + +void deltainfo_free(struct deltainfo *di) { if (!di) @@ -796,17 +808,12 @@ writefilestree(FILE *fp, git_tree *tree, const char *branch, const char *path) if (!(entry = git_tree_entry_byindex(tree, i)) || !(entryname = git_tree_entry_name(entry))) return -1; - r = snprintf(entrypath, sizeof(entrypath), "%s%s%s", - path, path[0] ? "/" : "", entryname); - if (r == -1 || (size_t)r >= sizeof(entrypath)) - errx(1, "path truncated: '%s%s%s'", - path, path[0] ? "/" : "", entryname); - - r = snprintf(filepath, sizeof(filepath), "file/%s%s%s.html", - path, path[0] ? "/" : "", entryname); + joinpath(entrypath, sizeof(entrypath), path, entryname); + + r = snprintf(filepath, sizeof(filepath), "file/%s.html", + entrypath); if (r == -1 || (size_t)r >= sizeof(filepath)) - errx(1, "path truncated: 'file/%s%s%s.html'", - path, path[0] ? "/" : "", entryname); + errx(1, "path truncated: 'file/%s.html'", entrypath); if (!git_tree_entry_to_object(&obj, repo, entry)) { switch (git_object_type(obj)) { @@ -991,18 +998,6 @@ err: } void -joinpath(char *buf, size_t bufsiz, const char *path, const char *path2) -{ - int r; - - r = snprintf(buf, bufsiz, "%s%s%s", - repodir, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2); - if (r == -1 || (size_t)r >= bufsiz) - errx(1, "path truncated: '%s%s%s'", - path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2); -} - -void usage(char *argv0) { fprintf(stderr, "%s [-c cachefile] repodir\n", argv0);