summaryrefslogtreecommitdiff
path: root/src/oid.c
diff options
context:
space:
mode:
authorRamsay Jones <ramsay@ramsay1.demon.co.uk>2010-06-02 19:16:28 +0100
committerRamsay Jones <ramsay@ramsay1.demon.co.uk>2010-06-07 19:44:04 +0100
commit552e23ba566d975b4dd48163b91021892504f021 (patch)
treee044baa468a1c74f9f9da36805445f6888358b49 /src/oid.c
parentf29249340c11b069e46b70fc145c1d7fbe213b94 (diff)
downloadlibgit2-552e23ba566d975b4dd48163b91021892504f021.tar.gz
Fix a bug in the git_oid_to_string() function
When git_oid_to_string() was passed a buffer size larger than GIT_OID_HEXSZ+1, the function placed the c-string NUL char at the wrong position. Fix the code to place the NUL at the end of the (possibly truncated) oid string. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Diffstat (limited to 'src/oid.c')
-rw-r--r--src/oid.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/oid.c b/src/oid.c
index 182859f51..0bc152bdf 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -106,7 +106,9 @@ char *git_oid_to_string(char *out, size_t n, const git_oid *oid)
if (n > 0) {
git_oid_fmt(str, oid);
- memcpy(out, str, n > GIT_OID_HEXSZ ? GIT_OID_HEXSZ : n);
+ if (n > GIT_OID_HEXSZ)
+ n = GIT_OID_HEXSZ;
+ memcpy(out, str, n);
}
out[n] = '\0';