mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
path.c: make get_pathname() call sites return const char *
Before the previous commit, get_pathname returns an array of PATH_MAX length. Even if git_path() and similar functions does not use the whole array, git_path() caller can, in theory. After the commit, get_pathname() may return a buffer that has just enough room for the returned string and git_path() caller should never write beyond that. Make git_path(), mkpath() and git_path_submodule() return a const buffer to make sure callers do not write in it at all. This could have been part of the previous commit, but the "const" conversion is too much distraction from the core changes in path.c. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
4ef9caf543
commit
dcf692625a
6
path.c
6
path.c
@@ -106,7 +106,7 @@ char *mkpathdup(const char *fmt, ...)
|
||||
return strbuf_detach(&sb, NULL);
|
||||
}
|
||||
|
||||
char *mkpath(const char *fmt, ...)
|
||||
const char *mkpath(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
struct strbuf *pathname = get_pathname();
|
||||
@@ -116,7 +116,7 @@ char *mkpath(const char *fmt, ...)
|
||||
return cleanup_path(pathname->buf);
|
||||
}
|
||||
|
||||
char *git_path(const char *fmt, ...)
|
||||
const char *git_path(const char *fmt, ...)
|
||||
{
|
||||
struct strbuf *pathname = get_pathname();
|
||||
va_list args;
|
||||
@@ -154,7 +154,7 @@ void home_config_paths(char **global, char **xdg, char *file)
|
||||
free(to_free);
|
||||
}
|
||||
|
||||
char *git_path_submodule(const char *path, const char *fmt, ...)
|
||||
const char *git_path_submodule(const char *path, const char *fmt, ...)
|
||||
{
|
||||
struct strbuf *buf = get_pathname();
|
||||
const char *git_dir;
|
||||
|
||||
Reference in New Issue
Block a user