summaryrefslogtreecommitdiff
path: root/src/oid.c
diff options
context:
space:
mode:
authorJ. David Ibáñez <jdavid.ibp@gmail.com>2011-09-30 19:08:48 +0200
committerJ. David Ibáñez <jdavid.ibp@gmail.com>2011-09-30 19:08:48 +0200
commite724b058b2fd3d3b58291205bb7aeeccc55c21c4 (patch)
treee8c26c7928d1ff9d734f6015e309d3717400c63d /src/oid.c
parent358a15fd65cdc56ddc02b3ea261851f20c7ac618 (diff)
downloadlibgit2-e724b058b2fd3d3b58291205bb7aeeccc55c21c4.tar.gz
oid: make git_oid_fromstrn support hex strings of odd length
This fixes issue #433. Signed-off-by: J. David Ibáñez <jdavid.ibp@gmail.com>
Diffstat (limited to 'src/oid.c')
-rw-r--r--src/oid.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/oid.c b/src/oid.c
index e2d16d537..2adaadcbd 100644
--- a/src/oid.c
+++ b/src/oid.c
@@ -34,15 +34,13 @@ static char to_hex[] = "0123456789abcdef";
int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
{
size_t p;
+ int v;
if (length > GIT_OID_HEXSZ)
length = GIT_OID_HEXSZ;
- if (length % 2)
- length--;
-
- for (p = 0; p < length; p += 2) {
- int v = (from_hex[(unsigned char)str[p + 0]] << 4)
+ for (p = 0; p < length - 1; p += 2) {
+ v = (from_hex[(unsigned char)str[p + 0]] << 4)
| from_hex[(unsigned char)str[p + 1]];
if (v < 0)
@@ -51,6 +49,12 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length)
out->id[p / 2] = (unsigned char)v;
}
+ if (length % 2) {
+ v = (from_hex[(unsigned char)str[p + 0]] << 4);
+ out->id[p / 2] = (unsigned char)v;
+ p += 2;
+ }
+
for (; p < GIT_OID_HEXSZ; p += 2)
out->id[p / 2] = 0x0;