Drop sprintf dependency
authorsvost <ya.nowa@yandex.ru>
Tue, 13 Sep 2016 08:05:37 +0000 (11:05 +0300)
committersvost <ya.nowa@yandex.ru>
Tue, 13 Sep 2016 08:05:37 +0000 (11:05 +0300)
src/uint256.h

index 114ef89..526aa71 100644 (file)
@@ -6,10 +6,10 @@
 #define BITCOIN_UINT256_H
 
 #include <limits>
-#include <string.h>
 #include <string>
 #include <vector>
-#include <stdint.h>
+#include <iomanip>
+#include <sstream>
 
 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)