From b40015c18a9acd7272d850df4389de98009a91f4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 24 Jun 2013 15:40:31 +0000 Subject: memory leak fix inside bytesToHex git-svn-id: http://svn.miranda-ng.org/main/trunk@5122 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/WhatsApp/src/WhatsAPI++/utilities.cpp | 33 ++++++------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'protocols/WhatsApp/src/WhatsAPI++/utilities.cpp') diff --git a/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp b/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp index 90d03dbdaa..7b7af160e7 100644 --- a/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp +++ b/protocols/WhatsApp/src/WhatsAPI++/utilities.cpp @@ -1,5 +1,4 @@ #include "utilities.h" -//#include "ApplicationData.h" #include #include #include @@ -11,9 +10,6 @@ #include #include -// #TODO Remove Miranda dependency -#include "../common.h" - namespace Utilities{ const static char digits[] = { @@ -84,7 +80,7 @@ std::string processIdentity(const std::string& id){ std::string buffer_str = reverseString(id); unsigned char digest[16]; - utils::md5string(buffer_str, digest); + md5_string(buffer_str, digest); buffer_str.clear(); for(int i =0; i < 16; i++){ @@ -132,7 +128,7 @@ std::string str(int64_t i, int radix ) { } int64_t randLong() { - std::srand(time(NULL)); + std::srand((unsigned)time(NULL)); int64_t r = (int64_t) ((char) (std::rand() % 256)); for (int i = 0; i < 7 ; i++) @@ -195,18 +191,14 @@ long long parseLongLong(const std::string& str) { return val; } -unsigned char* bytesToHex(unsigned char* bytes, int length) { - unsigned char* ret = new unsigned char[length*2]; +string bytesToHex(unsigned char* bytes, int length) { + string ret(length*2, ' '); + string::iterator p = ret.begin(); int i = 0; for (int c = 0; c < length; c++) { int ub = bytes[c]; - - if (ub < 0) - ub += 256; - ret[i] = forDigit(ub >> 4); - i++; - ret[i] = forDigit(ub % 16); - i++; + *p++ = forDigit(ub >> 4); + *p++ = forDigit(ub % 16); } return ret; @@ -218,15 +210,6 @@ unsigned char forDigit(int b) { return (unsigned char) (97 + b - 10); } -string md5String(const string& data) { - unsigned char md5_buffer[16+1]; - md5_buffer[16] = '\0'; - utils::md5string(data, md5_buffer); - std::string result((char*) Utilities::bytesToHex(md5_buffer, 16), 16*2); - - return result; -} - bool saveStringToFile(const string& data, const string& filePath) { std::ofstream out(filePath.c_str()); if (out.fail()) return false; @@ -261,7 +244,7 @@ bool saveBytesToFile(const string& data, const string& filePath) { vector* loadFileToBytes(const string& path) { vector* bytes = NULL; std::ifstream in(path.c_str(), ios::in | ios::binary | ios::ate); - long size = in.tellg(); + size_t size = in.tellg(); if (in.fail()) return NULL; in.seekg(0, ios::beg); -- cgit v1.2.3