Browse Source

Merge #9867: Replace remaining sprintf with snprintf

19cafc6 test: Replace remaining sprintf with snprintf (Wladimir J. van der Laan)
0a17714 uint256: replace sprintf with HexStr and reverse-iterator (Wladimir J. van der Laan)

Tree-SHA512: 2ba1dd4d25e1cbfff4d67b2f483448aa7c34ab5c799cddd48ba5826e5fa6df425abe35e244aaf4c52db9fccfb4d2a25a14bb4597bf9d1fce95991f270da6bb26
0.15
Wladimir J. van der Laan 8 years ago
parent
commit
f5ef8e9dd2
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 6
      src/test/dbwrapper_tests.cpp
  2. 5
      src/uint256.cpp

6
src/test/dbwrapper_tests.cpp

@ -277,7 +277,7 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering)
CDBWrapper dbw(ph, (1 << 20), true, false, false); CDBWrapper dbw(ph, (1 << 20), true, false, false);
for (int x=0x00; x<10; ++x) { for (int x=0x00; x<10; ++x) {
for (int y = 0; y < 10; y++) { for (int y = 0; y < 10; y++) {
sprintf(buf, "%d", x); snprintf(buf, sizeof(buf), "%d", x);
StringContentsSerializer key(buf); StringContentsSerializer key(buf);
for (int z = 0; z < y; z++) for (int z = 0; z < y; z++)
key += key; key += key;
@ -293,12 +293,12 @@ BOOST_AUTO_TEST_CASE(iterator_string_ordering)
seek_start = 0; seek_start = 0;
else else
seek_start = 5; seek_start = 5;
sprintf(buf, "%d", seek_start); snprintf(buf, sizeof(buf), "%d", seek_start);
StringContentsSerializer seek_key(buf); StringContentsSerializer seek_key(buf);
it->Seek(seek_key); it->Seek(seek_key);
for (int x=seek_start; x<10; ++x) { for (int x=seek_start; x<10; ++x) {
for (int y = 0; y < 10; y++) { for (int y = 0; y < 10; y++) {
sprintf(buf, "%d", x); snprintf(buf, sizeof(buf), "%d", x);
std::string exp_key(buf); std::string exp_key(buf);
for (int z = 0; z < y; z++) for (int z = 0; z < y; z++)
exp_key += exp_key; exp_key += exp_key;

5
src/uint256.cpp

@ -20,10 +20,7 @@ base_blob<BITS>::base_blob(const std::vector<unsigned char>& vch)
template <unsigned int BITS> template <unsigned int BITS>
std::string base_blob<BITS>::GetHex() const std::string base_blob<BITS>::GetHex() const
{ {
char psz[sizeof(data) * 2 + 1]; return HexStr(std::reverse_iterator<const uint8_t*>(data + sizeof(data)), std::reverse_iterator<const uint8_t*>(data));
for (unsigned int i = 0; i < sizeof(data); i++)
sprintf(psz + i * 2, "%02x", data[sizeof(data) - i - 1]);
return std::string(psz, psz + sizeof(data) * 2);
} }
template <unsigned int BITS> template <unsigned int BITS>

Loading…
Cancel
Save