From: ajkhoury aidankhoury@gmail.com
--- dlls/mspatcha/mspatcha_main.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/dlls/mspatcha/mspatcha_main.c b/dlls/mspatcha/mspatcha_main.c index 1d8744a85e4..9a184cf148d 100644 --- a/dlls/mspatcha/mspatcha_main.c +++ b/dlls/mspatcha/mspatcha_main.c @@ -54,14 +54,28 @@ static WCHAR *strdupAW(const char *src) return dst; }
-#define NIBBLE_CHAR(n) ((n) < 0xA) ? ('0' + (n)) : ('a' + ((n) - 0xA)) +static inline char nibble2char(unsigned char n) +{ + return (char)((n) < 0xA) ? ('0' + (n)) : ('a' + ((n) - 0xA)); +} + static inline void bin2hex(const unsigned char *bin, char *hexstr, size_t maxcount) { - for (size_t i = 0; i < maxcount; i++) { - *hexstr++ = NIBBLE_CHAR((*bin >> 4) & 0xf); - *hexstr++ = NIBBLE_CHAR(*bin++ & 0xf); + size_t i, n = 0; + for (i = 0; i < maxcount; i++) { + hexstr[n++] = nibble2char((bin[i] >> 4) & 0xf); + hexstr[n++] = nibble2char((bin[i] & 0xf)); + } + hexstr[n] = '\0'; +} + +static inline void dword2hex(unsigned int value, char *hexstr) +{ + size_t i; + for (i = 8; i > 0; --i, value >>= 4) { + hexstr[i-1] = nibble2char((value & 0xf)); } - *hexstr = '\0'; + hexstr[8] = '\0'; }
/***************************************************** @@ -403,7 +417,7 @@ BOOL WINAPI GetFilePatchSignatureByBuffer( if (signature_bufsize >= (sizeof(UINT32)*2+1)) { /* calculate CRC32 checksum of file buffer. */ filecrc = RtlComputeCrc32(0, file_buffer, file_size); - bin2hex((const unsigned char *)&filecrc, signature_buf, sizeof(UINT32)); + dword2hex(filecrc, signature_buf);
} else { SetLastError(ERROR_INSUFFICIENT_BUFFER);