fix joinpath(): use of global 'repodir', should be 'path'

use joinpath for another case.
This commit is contained in:
Hiltjo Posthuma 2016-05-03 20:42:46 +02:00
parent 2d8eb85f01
commit 543582034e
2 changed files with 28 additions and 33 deletions

View file

@ -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[])
{

View file

@ -76,6 +76,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)
{
@ -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);
joinpath(entrypath, sizeof(entrypath), path, entryname);
r = snprintf(filepath, sizeof(filepath), "file/%s%s%s.html",
path, path[0] ? "/" : "", 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)) {
@ -990,18 +997,6 @@ err:
return 0;
}
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)
{