From ac54bdbb5a329839458cd6c3f83dde2c0ddd5c83 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Thu, 17 Apr 2014 02:46:13 +0200 Subject: [PATCH] substitute non-portable printf format string the printf format "llx" can not be used on all platforms (for example, mingw uses a different name for it) this patch provides a function, that manually converts a 64-bit integer to a hex string Thx, Jpablon --- source/src/crypto.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/source/src/crypto.cpp b/source/src/crypto.cpp index 55567da7..23cbd3f1 100644 --- a/source/src/crypto.cpp +++ b/source/src/crypto.cpp @@ -760,13 +760,28 @@ bool hashstring(const char *str, char *result, int maxlen) return true; } +static const char *hashchunktoa(tiger::chunk h) // portable solution instead of printf("%llx") +{ // use next protocol bump to switch to hashstring() above! + static string buf; + static int bufidx; + bufidx = (bufidx + 1) & 0x3; + char *s = buf + (bufidx * 33) + 33; + *s-- = '\0'; + while(h) + { + *s-- = "0123456789abcdef"[h & 0xf]; + h >>= 4; + } + return s + 1; +} + const char *genpwdhash(const char *name, const char *pwd, int salt) { static string temp; formatstring(temp)("%s %d %s %s %d", pwd, salt, name, pwd, abs(PROTOCOL_VERSION)); tiger::hashval hash; tiger::hash((uchar *)temp, (int)strlen(temp), hash); - formatstring(temp)("%llx %llx %llx", hash.chunks[0], hash.chunks[1], hash.chunks[2]); + formatstring(temp)("%s %s %s", hashchunktoa(hash.chunks[0]), hashchunktoa(hash.chunks[1]), hashchunktoa(hash.chunks[2])); return temp; }