diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp --- a/src/test/dbwrapper_tests.cpp +++ b/src/test/dbwrapper_tests.cpp @@ -270,7 +270,7 @@ CDBWrapper dbw(ph, (1 << 20), true, false, false); for (int x = 0x00; x < 10; ++x) { for (int y = 0; y < 10; y++) { - sprintf(buf, "%d", x); + snprintf(buf, sizeof(buf), "%d", x); StringContentsSerializer key(buf); for (int z = 0; z < y; z++) key += key; @@ -282,12 +282,12 @@ std::unique_ptr it( const_cast(dbw).NewIterator()); for (int seek_start : {0, 5}) { - sprintf(buf, "%d", seek_start); + snprintf(buf, sizeof(buf), "%d", seek_start); StringContentsSerializer seek_key(buf); it->Seek(seek_key); for (int x = seek_start; x < 10; ++x) { for (int y = 0; y < 10; y++) { - sprintf(buf, "%d", x); + snprintf(buf, sizeof(buf), "%d", x); std::string exp_key(buf); for (int z = 0; z < y; z++) exp_key += exp_key; diff --git a/src/uint256.cpp b/src/uint256.cpp --- a/src/uint256.cpp +++ b/src/uint256.cpp @@ -17,11 +17,8 @@ } template std::string base_blob::GetHex() const { - char psz[sizeof(data) * 2 + 1]; - for (size_t i = 0; i < sizeof(data); i++) { - sprintf(psz + i * 2, "%02x", data[sizeof(data) - i - 1]); - } - return std::string(psz, psz + sizeof(data) * 2); + return HexStr(std::reverse_iterator(data + sizeof(data)), + std::reverse_iterator(data)); } template void base_blob::SetHex(const char *psz) {