From b647f57075aa526910e045afc5c9c511cefe5df7 Mon Sep 17 00:00:00 2001 From: svost Date: Tue, 13 Sep 2016 11:05:37 +0300 Subject: [PATCH] Drop sprintf dependency --- src/uint256.h | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/uint256.h b/src/uint256.h index 114ef89..526aa71 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -6,10 +6,10 @@ #define BITCOIN_UINT256_H #include -#include #include #include -#include +#include +#include using namespace std; @@ -297,10 +297,11 @@ public: std::string GetHex() const { - char psz[sizeof(pn)*2 + 1]; - for (unsigned int i = 0; i < sizeof(pn); i++) - sprintf(psz + i*2, "%02x", ((unsigned char*)pn)[sizeof(pn) - i - 1]); - return std::string(psz, psz + sizeof(pn)*2); + std::stringstream ss; + size_t pn_size = sizeof(pn) / sizeof(pn[0]); + for (size_t i = 1; i <= pn_size; i++) + ss << std::setfill('0') << std::setw(8) << std::setbase(16) << pn[pn_size-i]; + return ss.str(); } void SetHex(const char* psz) -- 1.7.1