From 75890e784ab82dfe7e159710eceb71fe56d941e0 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sat, 9 Aug 2014 08:31:55 +0000 Subject: Tox: fix to HexToBinString git-svn-id: http://svn.miranda-ng.org/main/trunk@10134 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_utils.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'protocols/Tox/src/tox_utils.cpp') diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index 093becbce4..3888da24bd 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -3,17 +3,20 @@ uint8_t *CToxProto::HexToBinString(char *hex_string) { // byte is represented by exactly 2 hex digits, so lenth of binary string - // is half of that of the hex one. only hex string with even length - // valid. the more proper implementation would be to check if strlen(hex_string) - // is odd and return error code if it is. we assume strlen is even. if it's not - // then the last byte just won't be written in 'ret'. - size_t i, len = (strlen(hex_string) / 2); - uint8_t *ret = (uint8_t*)mir_alloc(len); + // is half of that of the hex one. only hex string with even length valid. + // the more proper implementation would be to check if strlen(hex_string) + // is odd and return error code if it is. we assume strlen is even. + // if it's not then the last byte just won't be written in 'ret'. + int length = strlen(hex_string) / 2; + uint8_t *ret = (uint8_t*)mir_alloc(length); char *pos = hex_string; - for (i = 0; i < len; i++, pos += 2) + for (int i = 0; i < length; i++, pos += 2) { - sscanf(pos, "%2hhx", &ret[i]); + //sscanf(pos, "%2hhx", &ret[i]); + uint8_t byteval; + sscanf(pos, "%2hhx", &byteval); + ret[i] = byteval; } return ret; -- cgit v1.2.3