From eda99f62e61efca27ae24683c55fac329a4a8353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Mon, 9 Jan 2006 17:09:29 +0000 Subject: [PATCH] (hex_decode): support decoding odd number of characters, in the odd len case, the character ends up in the first byte in the lower nibble. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@16504 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/roken/hex.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/roken/hex.c b/lib/roken/hex.c index f5c5c268f..2daf247e9 100644 --- a/lib/roken/hex.c +++ b/lib/roken/hex.c @@ -91,7 +91,13 @@ hex_decode(const char *str, void *data, size_t len) if ((l/2) + (l&1) > len) return -1; + i = 0; + if (l & 1) { + p[0] = pos(str[0]); + str++; + p++; + } for (i = 0; i < l / 2; i++) p[i] = pos(str[i * 2]) << 4 | pos(str[(i * 2) + 1]); - return i; + return i + (l & 1); }