summaryrefslogtreecommitdiff
path: root/environment.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-09-24 21:07:03 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-09-25 17:18:18 (GMT)
commit75faa45ae0230b321bf72027b2274315d7e14e34 (patch)
tree3b4aa1b362078ba4db498a087f3330ffe7affbd8 /environment.c
parentb7115a350b5c01ce0ae7a8735e4235d4b2367b5f (diff)
downloadgit-75faa45ae0230b321bf72027b2274315d7e14e34.zip
git-75faa45ae0230b321bf72027b2274315d7e14e34.tar.gz
git-75faa45ae0230b321bf72027b2274315d7e14e34.tar.bz2
replace trivial malloc + sprintf / strcpy calls with xstrfmt
It's a common pattern to do: foo = xmalloc(strlen(one) + strlen(two) + 1 + 1); sprintf(foo, "%s %s", one, two); (or possibly some variant with strcpy()s or a more complicated length computation). We can switch these to use xstrfmt, which is shorter, involves less error-prone manual computation, and removes many sprintf and strcpy calls which make it harder to audit the code for real buffer overflows. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'environment.c')
-rw-r--r--environment.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/environment.c b/environment.c
index a533aed..c5b65f5 100644
--- a/environment.c
+++ b/environment.c
@@ -143,11 +143,8 @@ static char *git_path_from_env(const char *envvar, const char *git_dir,
const char *path, int *fromenv)
{
const char *value = getenv(envvar);
- if (!value) {
- char *buf = xmalloc(strlen(git_dir) + strlen(path) + 2);
- sprintf(buf, "%s/%s", git_dir, path);
- return buf;
- }
+ if (!value)
+ return xstrfmt("%s/%s", git_dir, path);
if (fromenv)
*fromenv = 1;
return xstrdup(value);