diff options
| author | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-09-30 16:55:05 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-10-01 00:41:08 +0200 |
| commit | a95aeb489f32fa7e570ecad12fc236f0a0e237a3 (patch) | |
| tree | bf3de013b88188c40e0f25aa218f7cf7b04d2d3c /src/transport_git.c | |
| parent | a70b3c7386aab50a3607731a0db1e69d01e11c73 (diff) | |
| download | libgit2-a95aeb489f32fa7e570ecad12fc236f0a0e237a3.tar.gz | |
Use git_buf in the git request
This is clearer and sidesteps the issue of what the return value of
snprintf is on the particular OS we're running on.
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
Diffstat (limited to 'src/transport_git.c')
| -rw-r--r-- | src/transport_git.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/transport_git.c b/src/transport_git.c index bcc612b43..a1c54ca83 100644 --- a/src/transport_git.c +++ b/src/transport_git.c @@ -35,10 +35,11 @@ typedef struct { */ static int gen_proto(char **out, int *outlen, const char *cmd, const char *url) { - char *delim, *repo, *ptr; + char *delim, *repo; char default_command[] = "git-upload-pack"; char host[] = "host="; int len; + git_buf buf = GIT_BUF_INIT; delim = strchr(url, '/'); if (delim == NULL) @@ -53,17 +54,16 @@ static int gen_proto(char **out, int *outlen, const char *cmd, const char *url) if (cmd == NULL) cmd = default_command; - len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 2; + len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 1 + 1; - *out = git__malloc(len); - if (*out == NULL) - return GIT_ENOMEM; + git_buf_grow(&buf, len); + + git_buf_printf(&buf, "%04x%s %s%c%s", len, cmd, repo, 0, host); + git_buf_put(&buf, url, delim - url); + git_buf_putc(&buf, '\0'); - *outlen = len - 1; - ptr = *out; - memset(ptr, 0x0, len); - /* We expect the return value to be > len - 1 so don't bother checking it */ - snprintf(ptr, len -1, "%04x%s %s%c%s%s", len - 1, cmd, repo, 0, host, url); + *outlen = len; + *out = buf.ptr; return GIT_SUCCESS; } |
